You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
1004 B

#include <stdlib.h>
#include <ev.h>
#define UNUSED(x) ((void)(x))
#define IOEV_NONE 0
#define IOEV_READ 1
#define IOEV_WRITE 2
#define IOEV_TIMEOUT 4
#define IOEV_ERROR 128
void ioev_event_callback(void* watcher, int revents);
struct ev_loop *ioev_ev_default_loop (unsigned int flags) {
return ev_default_loop(flags);
}
static void io_cb(struct ev_loop *loop, ev_io *w, int revents) {
int ev = 0;
UNUSED(loop);
if (revents & EV_READ) ev = ev | IOEV_READ;
if (revents & EV_WRITE) ev = ev | IOEV_WRITE;
if (revents & EV_ERROR) ev = ev | IOEV_ERROR;
ioev_event_callback(w->data, ev);
}
ev_io* ioev_io_watcher_new(void *watcher) {
ev_io *w = malloc(sizeof(ev_io));
ev_io_init(w, io_cb, -1, 0);
w->data = watcher;
return w;
}
void ioev_io_watcher_free(ev_io *w) {
free(w);
}
void ioev_io_set(ev_io *w, int fd, int ev) {
int events = 0;
if (ev & IOEV_READ) events = events | EV_READ;
if (ev & IOEV_WRITE) events = events | EV_WRITE;
ev_io_set(w, fd, events);
}