전체 글 썸네일형 리스트형 Haskell - The 1st Note As I worked as a programmer, I've written a lot and been reading many programs written by other authors. Sometimes I found that I enjoys doing this job - understanding, realizing, creating and solving problems. And when I works with other people as a team to solve, figure out, or whatever, I fill like we are talking each other via our code. Code delivers author's idea, considerations, perspectiv.. 더보기 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_.. 더보기 이전 1 ··· 5 6 7 8 9 10 11 ··· 36 다음