help icon indicating copy to clipboard operation
help copied to clipboard

On Windows, why libuv postpone I/O callback invocation to next round of the loop?

Open kbridge opened this issue 7 years ago • 1 comments

Hi everyone.

After reading some docs, I learn that most I/O callbacks get called in the POLL stage of the loop (once their I/Os complete).

For example:

Doc1: An Introduction to libuv

All I/O related handles that were monitoring a given file descriptor for a read or write operation get their callbacks called at this point.

Doc2: The Node.js Event Loop

poll: retrieve new I/O events; execute I/O related callbacks

I read the code for Linux and confirm this. But when I come to read the code for Windows, I feel shocked. It just inserts the callbacks into the pending req list. No one gets called right after polling.

    success = GetQueuedCompletionStatusEx(loop->iocp,
                                          overlappeds,
                                          ARRAY_SIZE(overlappeds),
                                          &count,
                                          timeout,
                                          FALSE);

    if (success) {
      for (i = 0; i < count; i++) {
        /* Package was dequeued, but see if it is not a empty package
         * meant only to wake us up.
         */
        if (overlappeds[i].lpOverlapped) {
          req = uv_overlapped_to_req(overlappeds[i].lpOverlapped);
          uv_insert_pending_req(loop, req);
        }
      }

This behavior is different from what the doc says. I even write a test program to confirm.

So my question is, is this being done deliberately and considered OK? If yes, why?

kbridge avatar Jan 17 '19 14:01 kbridge

Anybody here...? I guess this should be a simple question. :pensive:

kbridge avatar Jan 21 '19 12:01 kbridge