struct uloop_timeout *first_timeout;
static int poll_fd;
-static bool cancel;
+bool uloop_cancelled = false;
#ifdef USE_KQUEUE
if (changed & ULOOP_WRITE) {
uint16_t kflags = get_flags(flags, ULOOP_WRITE);
- EV_SET(&ev[nev++], fd->fd, EVFILT_READ, kflags, 0, 0, fd);
+ EV_SET(&ev[nev++], fd->fd, EVFILT_WRITE, kflags, 0, 0, fd);
}
if (nev && (kevent(poll_fd, ev, nev, NULL, 0, &timeout) == -1))
struct timespec ts;
int nfds, n;
- if (timeout < 0) {
- ts.tv_sec = 0;
- ts.tv_nsec = 0;
- } else {
+ if (timeout > 0) {
ts.tv_sec = timeout / 1000;
ts.tv_nsec = timeout * 1000000;
}
- nfds = kevent(poll_fd, NULL, 0, events, ARRAY_SIZE(events), &ts);
+ nfds = kevent(poll_fd, NULL, 0, events, ARRAY_SIZE(events), timeout > 0 ? &ts : NULL);
for(n = 0; n < nfds; ++n)
{
struct uloop_fd *u = events[n].udata;
unsigned int fl;
int ret;
- if (!sock->registered) {
+ if (!sock->registered && !(flags & ULOOP_BLOCKING)) {
fl = fcntl(sock->fd, F_GETFL, 0);
fl |= O_NONBLOCK;
fcntl(sock->fd, F_SETFL, fl);
static void uloop_handle_sigint(int signo)
{
- cancel = true;
+ uloop_cancelled = true;
}
static void uloop_setup_signals(void)
void uloop_end(void)
{
- cancel = true;
+ uloop_cancelled = true;
}
void uloop_run(void)
struct timeval tv;
uloop_setup_signals();
- while(!cancel)
+ while(!uloop_cancelled)
{
gettimeofday(&tv, NULL);
uloop_process_timeouts(&tv);