For detailed examples please see tests/ directory in the code.
Brief overview:
jioloop_init();
jioloop_signal_handle(SIGINT, JIOLOOP_SIG_HANDLE, sig_int, NULL); struct timespec interval = {0, 500000000}; jioloop_timeout_add(JIOLOOP_TIMEOUT_INTERVAL, &interval, timeout_cbk, NULL); time_t now = time(NULL); jioloop_timer_add(now + 5, timer_cbk, NULL); int fd; fd = socket()... jioloop_fd_add(fd, JIOLOOP_FD_READ, fd_cbk, NULL);
jioloop_loop();
int sig_int(int sig, void *data) { jioloop_exit(); return 0; }
At this point jioloop_loop();
will return.
int timeout_cbk(void *id, jioloop_timeout_type type, void *data) { if (count++ > 1000) jioloop_timeout_remove(id); return 0; }
int fd_read(int fd, jioloop_fd_what what, void *data) { jioloop_fd_remove(fd, JIOLOOP_FD_READ, fd_read, data); jioloop_fd_add(fd, JIOLOOP_FD_WRITE, fd_write, data); return 0; }