aboutsummaryrefslogtreecommitdiff
path: root/eventloop.h
blob: 490d515f5a259223f5b0ffa1bcaf2cc92b78187f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <sys/epoll.h>

#include "tsocket.h"

#ifndef __EVENT_LOOP_H
#define __EVENT_LOOP_H

#define EVENT_LOOP_MAX_EVENTS 1024

struct eventLoop {
    int epollfd;
    struct epoll_event events[EVENT_LOOP_MAX_EVENTS];
    int size;
};

struct event {
    int fd;
    struct eventLoop *el;
    void *data;
    void (*handle)(struct event *ev);
    void (*delete)(struct event *ev);
};

struct eventLoop *eventLoopNew();
int eventLoopWait(struct eventLoop *el, int timeout);
int eventLoopAdd(struct eventLoop *el, struct event *ev, int flag);
int eventLoopDel(struct eventLoop *el, struct event *ev);
struct event *eventLoopGet(struct eventLoop *el, int index);
void eventLoopLoop(struct eventLoop *el);

#endif