Commit b53d39a
committed
Our select() function is emulated using poll(), which is a sensible thing
to do. However, it did several things wrong that this patch fixes. Thanks
to Paolo Bonzini for finding these problems (see issue #35).
1. When poll() returned a bare POLLHUP, without POLLIN, our select() didn't
return a read event. But nothing in the manpages guarantees that POLLHUP
is accompanied by POLLIN, and some special file implementations might
forget it. As an example, in Linux POLLHUP without POLLIN is common.
But POLLHUP on its own already means that there's nothing more to read,
so a read() will return immediately without blocking - and therefore
select() needs to turn on the readable bit for this fd.
2. Similarly, a bare POLLRDHUP should turn on the writable bit: The
reader on this file hug up, so a write will fail immediately.
3. Our poll() and select() confused what POLLERR means. POLLERR does not
mean poll() found a bad file descriptor - there is POLLNVAL for that.
So this patch fixes poll() to set POLLNVAL, not POLLERR, and select()
to return with errno=EBADF when it sees POLLNVAL, not POLLERR.
4. Rather, POLLERR means the file descriptor is in an error state, so every
read() or write() will return immediately (with an error). So when we see
it, we need to turn on both read and write bits in this case.
5. The meaning of "exceptfds" isn't clear in any manual page, and it
seems there're a lot of opinions on what it might mean. In this patch I
did what Paolo suggested, which is to set the except bit when POLLPRI.
(I don't set exceptfds on POLLERR, or any other case).
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>1 parent ea4cb9f commit b53d39a
2 files changed
+17
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
119 | 124 | | |
120 | | - | |
| 125 | + | |
121 | 126 | | |
122 | | - | |
| 127 | + | |
123 | 128 | | |
124 | 129 | | |
125 | 130 | | |
126 | 131 | | |
127 | | - | |
| 132 | + | |
128 | 133 | | |
129 | | - | |
| 134 | + | |
130 | 135 | | |
131 | 136 | | |
132 | 137 | | |
133 | | - | |
134 | | - | |
| 138 | + | |
| 139 | + | |
135 | 140 | | |
136 | | - | |
| 141 | + | |
137 | 142 | | |
| 143 | + | |
138 | 144 | | |
139 | | - | |
140 | | - | |
141 | | - | |
| 145 | + | |
| 146 | + | |
142 | 147 | | |
143 | 148 | | |
144 | 149 | | |
| |||
0 commit comments