You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
POLLHUP should set the file descriptor's bit in rfds, POLLERR should set it in wfds and rfds (but not xfds), POLLPRI should set it in xfds. As to POLLRDHUP, I guess it should set wfds since writes would always fail with EPIPE and thus not block... but Linux just ignores in its select() code which is a wrapper for poll() like OSv's.
Seriously... What an awesome project, and the C++ code is the nicest I've ever seen! Keep it up!
Hi Paulo, thanks for the compliments, and for the bug report.
I'm looking into select() and pipe() now, to look into these edge cases (and add them to the unit tests, e.g., tests/tst-pipe.cc).
What I'm wondering, shouldn't POLLHUP always be accompanied by a POLLIN? If poll returned POLLIN|POLLHUP instead of just POLLHUP, the current test in select() would already be fine. If poll returns POLLHUP only, our select() isn't correct. So I need to see what we did in OSv. As far as I know, this issue (whether to return both POLLIN and POLLHUP, or only one) is different in different Unix implementations.
But you're right, we can write a select() wrapper that will work over poll() in any Unix-like implementation, and it should check for POLLIN|POLLHUP.
It also seems our select()'s handling of exceptfds isn't accurate, to say the least (we don't even look at it when building the poll argument).
Yeah, I didn't really look that much into the pipe and socket code that produces POLLIN/POLLHUP. Always returning POLLIN|POLLHUP would be the sane thing to do, but since effectively anyone can build their own pollable file descriptor in OSv I think it's more robust to not assume that.
Based on some quick testing, the pipe_buffer.cc methods have the following differences wrt Linux:
int pipe_buffer::read_events_unlocked()
{
int ret = 0;
ret |= !q.empty() ? POLLIN : 0;
ret |= !sender ? POLLRDHUP : 0;
Linux never returns POLLRDHUP for pipes (I'd get rid of it completely :) as it seems pretty obscure and you're using BSD networking code that doesn't have it). It returns POLLHUP if there is no sender. It can return POLLIN|POLLHUP so the logic is otherwise okay.
return ret;
}
int pipe_buffer::write_events_unlocked()
{
if (!receiver) {
return POLLHUP;
}
Linux here returns POLLOUT|POLLERR, matching the fact that the write will return EPIPE.
int ret = 0;
ret |= q.size() < max_buf ? POLLOUT : 0;
return ret;
}
Activity
nyh commentedon Sep 18, 2013
Hi Paulo, thanks for the compliments, and for the bug report.
I'm looking into select() and pipe() now, to look into these edge cases (and add them to the unit tests, e.g., tests/tst-pipe.cc).
What I'm wondering, shouldn't POLLHUP always be accompanied by a POLLIN? If poll returned POLLIN|POLLHUP instead of just POLLHUP, the current test in select() would already be fine. If poll returns POLLHUP only, our select() isn't correct. So I need to see what we did in OSv. As far as I know, this issue (whether to return both POLLIN and POLLHUP, or only one) is different in different Unix implementations.
But you're right, we can write a select() wrapper that will work over poll() in any Unix-like implementation, and it should check for POLLIN|POLLHUP.
It also seems our select()'s handling of exceptfds isn't accurate, to say the least (we don't even look at it when building the poll argument).
bonzini commentedon Sep 18, 2013
Yeah, I didn't really look that much into the pipe and socket code that produces POLLIN/POLLHUP. Always returning POLLIN|POLLHUP would be the sane thing to do, but since effectively anyone can build their own pollable file descriptor in OSv I think it's more robust to not assume that.
Based on some quick testing, the pipe_buffer.cc methods have the following differences wrt Linux:
Linux never returns POLLRDHUP for pipes (I'd get rid of it completely :) as it seems pretty obscure and you're using BSD networking code that doesn't have it). It returns POLLHUP if there is no sender. It can return POLLIN|POLLHUP so the logic is otherwise okay.
Linux here returns POLLOUT|POLLERR, matching the fact that the write will return EPIPE.
Our select() function is emulated using poll(), which is a sensible t…
nyh commentedon Sep 30, 2014
Commits fixing most of the bugs reported in this patch:
commit 554e80f
commit 3511724
commit f6d134b
commit b53d39a
poll: generate POLLERR even if no events requested