37 ms·
Is this error only happening when the polled set contains no file descriptors at all? I personally would not have guessed that this usage is valid at all, sinc
by Matthias247 10y ago
Is this error only happening when the polled set contains no file descriptors at all?
I personally would not have guessed that this usage is valid at all, since it would always for the timout. If no timeout is specified there's then even the question if it should wait infinitely (makes no sense but matches the normal poll-without-timeout behavior) or not at all.
- quotemstr 10y agoReturning immediately when nfds==0 is silly: this behavior would introduce a needless discontinuity in the API and requires special-case code in all callers, and all for no benefit. It's like those bad implementations of read_something functions that signal error in the case of reading zero bytes instead of more sanely just doing nothing successfully.
- JdeBP 10y agoIt's subtler than that. It's returning immediately when the number of file descriptors that it fails to add to a kqueue (that is actually going to do the work and that it is setting up) is the same as the total number of file descriptors passed, which it is when they are both zero.
- noselasd 10y agoYes. The timeout is specified, but no file descriptors is given. (so calling poll() behaves like sleep/usleep ). This behavior is explicitly described in posix, worked prior to OSX 10.12, but behaves differently as of OSX10.12
- mikepurvis 10y agoIsn't the distinction that poll/select will only block only the current thread, whereas sleep may block the whole process?
- to3m 10y agosleep blocks the calling thread: http://pubs.opengroup.org/onlinepubs/009695399/functions/sleep.html http://pubs.opengroup.org/onlinepubs/009695399/functions/sle...
- deathanatos 10y ago> This behavior is explicitly described in posix Where? Here's the [POSIX specification of poll][1], for reference. Nowhere in there can I find that it explicitly specifies the behavior of an empty-set poll. The only really relevant paragraph, with relation to the timeout arg is this one: > If none of the defined events have occurred on any selected file descriptor, poll() shall wait at least timeout milliseconds for an event to occur on any of the selected file descriptors. If the value of timeout is 0, poll() shall return immediately. If the value of timeout is -1, poll() shall block until a requested event occurs or until the call is interrupted. But "if none of the defined events have occurred" isn't really evaluable when there aren't any defined events in the first place; the answer is undefined because the question is wrong. Thus, it seems to me that this behavior is undefined, as far as POSIX is concerned. (I wonder if this could be rephrased as, if ∃ fd∈∅ where none of the defined events have occurred on fd, then poll shall wait timeout…; this if is false (not undefined), so is should not wait the timeout. But then, the standard leaves us wondering what it should do, if not that. I think this reinterpretation depends on equating "any" with "at least one", though.) (Having poll wait the timeout when passed the empty set certainly seems useful, but whether or not that's standard is a different question.) [1]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/po...
- lmm 10y ago> "if none of the defined events have occurred" isn't really evaluable when there aren't any defined events in the first place It absolutely is evaluable. If there are no defined events then none of them has occurred. There's nothing weird or undefined about that; the empty set is empty.
- eridius 10y agoI don't think it's evaluable. > If none of the defined events have occurred on any selected file descriptor Note the "on any selected file descriptor". If there aren't any selected file descriptors to begin with, then the question doesn't even make sense. I can see how you could read it as saying it should sleep, but strictly speaking it seems like this is undefined behavior.