diff options
author | Ron Yorston <rmy@pobox.com> | 2023-03-03 11:29:58 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-03-03 11:29:58 +0000 |
commit | 0678b843f10191abadc5f47cef9a8ab6a29b7326 (patch) | |
tree | 0ebbaaeb7726c5ed8d881370526e256c497b501e | |
parent | e9ea698021018cb94e6075598eda0c01cf61b28e (diff) | |
download | busybox-w32-0678b843f10191abadc5f47cef9a8ab6a29b7326.tar.gz busybox-w32-0678b843f10191abadc5f47cef9a8ab6a29b7326.tar.bz2 busybox-w32-0678b843f10191abadc5f47cef9a8ab6a29b7326.zip |
win32: revise poll(2) for use in nc
Upstream commit 5b3b468ec (nc: use poll() instead of select())
changed `nc` to use poll(2) instead of select(2), obviously.
In busybox-w32 select(2) had already been hacked to support `nc`.
To avoid hacking poll(2) too the upstream change was reverted
(c2002eae3). Later `nc` was altered to include the code for both
poll and select (3c85cc0c4).
Make the changes necessary for poll(2) to work with `nc` on Windows.
These are all in the function windows_compute_revents().
Treat a character file that isn't a console as a normal file.
Without this `nc 127.0.0.1 1234 </dev/null` doesn't work.
Return 0 instead of POLLHUP if GetNumberOfConsoleInputEvents()
indicates no events are available. Without this communication
between two instances of `nc` which are both using keyboard
input isn't as asynchronous as one would like.
Only process key press events: key releases are ignored. Without
this `nc 127.0.0.1 1234` won't receive anything from the server
until the local user presses a key.
In the default case, which now includes disk files and character
files, detect polling for reads as well as writes. Without this
`nc 127.0.0.1 1234 <local_file` doesn't work.
-rw-r--r-- | win32/poll.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/win32/poll.c b/win32/poll.c index 18f8795ac..dd3b2d1cb 100644 --- a/win32/poll.c +++ b/win32/poll.c | |||
@@ -219,10 +219,8 @@ windows_compute_revents (HANDLE h, int *p_sought) | |||
219 | return happened; | 219 | return happened; |
220 | 220 | ||
221 | case FILE_TYPE_CHAR: | 221 | case FILE_TYPE_CHAR: |
222 | ret = WaitForSingleObject (h, 0); | 222 | // Fall through to default case for non-console, e.g. /dev/null. |
223 | if (!IsConsoleHandle (h)) | 223 | if (IsConsoleHandle (h)) { |
224 | return ret == WAIT_OBJECT_0 ? *p_sought & ~(POLLPRI | POLLRDBAND) : 0; | ||
225 | |||
226 | nbuffer = avail = 0; | 224 | nbuffer = avail = 0; |
227 | bRet = GetNumberOfConsoleInputEvents (h, &nbuffer); | 225 | bRet = GetNumberOfConsoleInputEvents (h, &nbuffer); |
228 | if (bRet) | 226 | if (bRet) |
@@ -230,7 +228,8 @@ windows_compute_revents (HANDLE h, int *p_sought) | |||
230 | /* Input buffer. */ | 228 | /* Input buffer. */ |
231 | *p_sought &= POLLIN | POLLRDNORM; | 229 | *p_sought &= POLLIN | POLLRDNORM; |
232 | if (nbuffer == 0) | 230 | if (nbuffer == 0) |
233 | return POLLHUP; | 231 | // Having no unread events isn't an error condition. |
232 | return 0 /* was POLLHUP */; | ||
234 | if (!*p_sought) | 233 | if (!*p_sought) |
235 | return 0; | 234 | return 0; |
236 | 235 | ||
@@ -240,7 +239,9 @@ windows_compute_revents (HANDLE h, int *p_sought) | |||
240 | return POLLHUP; | 239 | return POLLHUP; |
241 | 240 | ||
242 | for (i = 0; i < avail; i++) | 241 | for (i = 0; i < avail; i++) |
243 | if (irbuffer[i].EventType == KEY_EVENT) | 242 | // Ignore key release. |
243 | if (irbuffer[i].EventType == KEY_EVENT && | ||
244 | irbuffer[i].Event.KeyEvent.bKeyDown) | ||
244 | return *p_sought; | 245 | return *p_sought; |
245 | return 0; | 246 | return 0; |
246 | } | 247 | } |
@@ -250,13 +251,16 @@ windows_compute_revents (HANDLE h, int *p_sought) | |||
250 | *p_sought &= POLLOUT | POLLWRNORM | POLLWRBAND; | 251 | *p_sought &= POLLOUT | POLLWRNORM | POLLWRBAND; |
251 | return *p_sought; | 252 | return *p_sought; |
252 | } | 253 | } |
254 | } | ||
255 | /* fall through */ | ||
253 | 256 | ||
254 | default: | 257 | default: |
255 | ret = WaitForSingleObject (h, 0); | 258 | ret = WaitForSingleObject (h, 0); |
256 | if (ret == WAIT_OBJECT_0) | 259 | if (ret == WAIT_OBJECT_0) |
257 | return *p_sought & ~(POLLPRI | POLLRDBAND); | 260 | return *p_sought & ~(POLLPRI | POLLRDBAND); |
258 | 261 | ||
259 | return *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND); | 262 | // Add (POLLIN | POLLRDNORM). Why only support write? |
263 | return *p_sought & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND); | ||
260 | } | 264 | } |
261 | } | 265 | } |
262 | 266 | ||