(三)ae 事件驱动

时间:2022-10-04 19:56:41

A simple event-driven programming library.
Originally I wrote this code for the Jim's event-loop (Jim is a Tcl interpreter) but later translated it in form of a library for easy reuse.

(三)ae 事件驱动

可以参考:
Redis源码分析(二十)--- ae事件驱动

示例

main.c

#include "ae.h"

#include <iostream>
using namespace std;

void Proc(struct aeEventLoop *eventLoop, int fd, void *clientData, int mask)
{
    cout<<"proc"<<endl;
    aeStop(eventLoop);
}

int main()
{
    cout<<"hello world"<<endl;

    aeEventLoop *loop = aeCreateEventLoop(64);
    if(loop != nullptr) {
        //cout<<loop->setsize<<endl;
        cout<<aeGetSetSize(loop)<<endl;
        cout<<aeGetApiName()<<endl;

        /*long seconds, milliseconds;
        aeGetTime(&seconds, &milliseconds);
        cout<<seconds<<endl<<milliseconds<<endl;*/

        aeCreateFileEvent(loop, 0, 1, Proc, nullptr);

        aeMain(loop);
        //aeStop(loop);
        aeDeleteEventLoop(loop);
    }

    return 0;
}