aboutsummaryrefslogtreecommitdiff
path: root/eventloop.h
blob: 9aafb683940908715745c8e6b0a00af5b26f1e7e (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;
    void *data;
    int (*handle)(void *data);
    void (*delete)(void *data);
};

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);
struct event *eventNew(void *data, int fd, void (*handle), void (*delete));

#endif