node.js - I'm confused with the epoll in libuv network I/O -
these days i'm reading source code of node.js, here i'm confused:
in libuv's uv__io_poll
function, firstly, in while loop pool out every i/o watchers , events interseted about, , run uv__epoll_ctl()
register events system's epoll.
while (!queue_empty(&loop->watcher_queue)) { q = queue_head(&loop->watcher_queue); queue_remove(q); queue_init(q); w = queue_data(q, uv__io_t, watcher_queue); assert(w->pevents != 0); assert(w->fd >= 0); assert(w->fd < (int) loop->nwatchers); e.events = w->pevents; e.data = w->fd; if (w->events == 0) op = uv__epoll_ctl_add; else op = uv__epoll_ctl_mod; if (uv__epoll_ctl(loop->backend_fd, op, w->fd, &e)) { if (errno != eexist) abort(); if (uv__epoll_ctl(loop->backend_fd, uv__epoll_ctl_mod, w->fd, &e)) abort(); } w->events = w->pevents; }
and in infinite loop run uv__epoll_wait()
wait events coming:
for(;;){ nfds = uv__epoll_wait(loop->backend_fd, events, array_size(events), timeout); //... run callback every events. }
but function blocked loop. if there comes new watchers loop->watcher_queuue
, can't registered in time.
so how epool work ensure while (!queue_empty(&loop->watcher_queue)){}
can run again in time(it means goto next event loop).
how long every event loop runs?
Comments
Post a Comment