diff options
| author | Ron Yorston <rmy@pobox.com> | 2024-10-25 07:47:11 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2024-10-25 07:47:11 +0100 |
| commit | 93678239bba121c8cb88c32aa5ea410b52c3f293 (patch) | |
| tree | dec83f07fb98510e339e1bdd3026b97dcbdc4662 | |
| parent | b4c70222a200314ce3805e96f7de94ceb57c79ea (diff) | |
| download | busybox-w32-93678239bba121c8cb88c32aa5ea410b52c3f293.tar.gz busybox-w32-93678239bba121c8cb88c32aa5ea410b52c3f293.tar.bz2 busybox-w32-93678239bba121c8cb88c32aa5ea410b52c3f293.zip | |
win32: workaround for pipe writability in poll(2)
A CGI script was found to hang when a large amount of data was
posted:
#!/bin/sh
echo "Content-type: text/plain;"
echo
if [ "$REQUEST_METHOD" = "POST" ]; then
dd of=my.dat bs=1 count=${CONTENT_LENGTH}
echo -n "success."
else
echo -n "error!"
fi
This appears to be due to problems determining whether a pipe is
writable on Windows. The Git for Windows project has a workaround
in their copy of GNUlib's poll(2) implementation. The details are
in the commit message:
https://github.com/git-for-windows/git/commit/94f4d01932279c419844aa708bec31a26056bc6b
Apply the same workaround here.
Saves 220-272 bytes.
(GitHub issue #468)
| -rw-r--r-- | win32/poll.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/win32/poll.c b/win32/poll.c index b39732887..fb95adea7 100644 --- a/win32/poll.c +++ b/win32/poll.c | |||
| @@ -170,14 +170,17 @@ windows_compute_revents (HANDLE h, int *p_sought) | |||
| 170 | INPUT_RECORD *irbuffer; | 170 | INPUT_RECORD *irbuffer; |
| 171 | DWORD avail, nbuffer; | 171 | DWORD avail, nbuffer; |
| 172 | BOOL bRet; | 172 | BOOL bRet; |
| 173 | #if 0 | ||
| 173 | IO_STATUS_BLOCK iosb; | 174 | IO_STATUS_BLOCK iosb; |
| 174 | FILE_PIPE_LOCAL_INFORMATION fpli; | 175 | FILE_PIPE_LOCAL_INFORMATION fpli; |
| 175 | static PNtQueryInformationFile NtQueryInformationFile; | 176 | static PNtQueryInformationFile NtQueryInformationFile; |
| 176 | static BOOL once_only; | 177 | static BOOL once_only; |
| 178 | #endif | ||
| 177 | 179 | ||
| 178 | switch (GetFileType (h)) | 180 | switch (GetFileType (h)) |
| 179 | { | 181 | { |
| 180 | case FILE_TYPE_PIPE: | 182 | case FILE_TYPE_PIPE: |
| 183 | #if 0 | ||
| 181 | if (!once_only) | 184 | if (!once_only) |
| 182 | { | 185 | { |
| 183 | NtQueryInformationFile = (PNtQueryInformationFile) | 186 | NtQueryInformationFile = (PNtQueryInformationFile) |
| @@ -185,6 +188,7 @@ windows_compute_revents (HANDLE h, int *p_sought) | |||
| 185 | "NtQueryInformationFile"); | 188 | "NtQueryInformationFile"); |
| 186 | once_only = TRUE; | 189 | once_only = TRUE; |
| 187 | } | 190 | } |
| 191 | #endif | ||
| 188 | 192 | ||
| 189 | happened = 0; | 193 | happened = 0; |
| 190 | if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0) | 194 | if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0) |
| @@ -197,6 +201,14 @@ windows_compute_revents (HANDLE h, int *p_sought) | |||
| 197 | 201 | ||
| 198 | else | 202 | else |
| 199 | { | 203 | { |
| 204 | /* The writability of a pipe can't be detected reliably on Windows. | ||
| 205 | * Just say it's OK. | ||
| 206 | * | ||
| 207 | * Details: | ||
| 208 | * | ||
| 209 | * https://github.com/git-for-windows/git/commit/94f4d01932279c419844aa708bec31a26056bc6b | ||
| 210 | */ | ||
| 211 | #if 0 | ||
| 200 | /* It was the write-end of the pipe. Check if it is writable. | 212 | /* It was the write-end of the pipe. Check if it is writable. |
| 201 | If NtQueryInformationFile fails, optimistically assume the pipe is | 213 | If NtQueryInformationFile fails, optimistically assume the pipe is |
| 202 | writable. This could happen on Windows 9x, where | 214 | writable. This could happen on Windows 9x, where |
| @@ -214,6 +226,7 @@ windows_compute_revents (HANDLE h, int *p_sought) | |||
| 214 | || fpli.WriteQuotaAvailable >= PIPE_BUF | 226 | || fpli.WriteQuotaAvailable >= PIPE_BUF |
| 215 | || (fpli.OutboundQuota < PIPE_BUF && | 227 | || (fpli.OutboundQuota < PIPE_BUF && |
| 216 | fpli.WriteQuotaAvailable == fpli.OutboundQuota)) | 228 | fpli.WriteQuotaAvailable == fpli.OutboundQuota)) |
| 229 | #endif | ||
| 217 | happened |= *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND); | 230 | happened |= *p_sought & (POLLOUT | POLLWRNORM | POLLWRBAND); |
| 218 | } | 231 | } |
| 219 | return happened; | 232 | return happened; |
