본문 바로가기

misc./libev & libeio

libeio - example: cp #include #include #include #include #include static struct ev_loop* loop; static ev_idle repeat_watcher; static ev_async ready_watcher; static const char* src; static const char* dst; struct file_copy { int srcfd; int dstfd; int offset; char buffer[1024]; }; int srcfd; int dstfd; int offset; char buffer[1024]; static int copy(struct file_copy* data); void end_copy(struct file_copy* data) { free(.. 더보기
libev - example: stdin #include #include #include ev_io stdin_watcher; // callback for io static void io_cb(EV_P_ struct ev_io* w, int revents) { char buffer[1024]; int res; printf("io event - fd: %d, event: %d\n", w->fd, revents); if ((res = read(w->fd, buffer, sizeof(buffer))) > 0) { printf("read %d bytes: %s", res, buffer); } else { perror("failed to read"); } } int main() { // use the default event loop struct ev_.. 더보기
libev - example: timer #include ev_timer timeout_watcher; // callback for timeout static void timeout_cb(EV_P_ struct ev_timer* w, int revents) { puts("timeout"); } int main() { // use the default event loop struct ev_loop* loop = ev_default_loop(0); // initialize an timer watcher // the timeout event will occur after 1sec, and repeat every 3sec. ev_timer_init(&timeout_watcher, timeout_cb, 1, 3); ev_timer_start(loop, .. 더보기
ANATOMY OF A WATCHER ANATOMY OF A WATCHER A watcher is a structure that you create and register to record your interest in some event. For instance, if you want to wait for STDIN to become readable, you would create an ev_io watcher for that. static void my_cb (struct ev_loop *loop, struct ev_io *w, int revents) { ev_io_stop (w); ev_break (loop, EVUNLOOP_ALL); } struct ev_loop *loop = ev_default_loop (0); struct ev_.. 더보기
libev - some functions controlling the event loop Functions Controlling the Event Loop An event loop is described by a struct ev_loop*.The library knows two types of such loop, the default loop, and dynamically created loops. struct ev_loop *ev_default_loop(unsigned int flags)This will initialize the default event loop if it hasn't been initialized yet and return it.If the default loop could not be initialized, return false.If it already was in.. 더보기
libev, libeio Documentationlibev: http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.podlibeio: http://pod.tst.eu/http://cvs.schmorp.de/libeio/eio.pod What is libev?libev is a full-featured and high-performance event loop that is loosely modelled after libevent.benchmark: http://libev.schmorp.de/bench.html What is libeio?libeio is a library that provides truly asynchronous POSIX I/O. 더보기