[newlib-cygwin/cygwin-3_5-branch] Cygwin: select: set pipe writable only if PIPE_BUF bytes left
Corinna Vinschen
corinna@sourceware.org
Thu Aug 22 20:38:20 GMT 2024
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=555afcb2f3a6638084912ce1011bd6acef59ea79
commit 555afcb2f3a6638084912ce1011bd6acef59ea79
Author: Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Sun Aug 18 21:55:52 2024 +0200
Commit: Corinna Vinschen <corinna@vinschen.de>
CommitDate: Thu Aug 22 19:58:49 2024 +0200
Cygwin: select: set pipe writable only if PIPE_BUF bytes left
Linux select(2) returns the pipe as writable if at least one
free page (4K onl most systems) is left in a page-oriented buffer
handling. This is the same as PIPE_BUF.
Emulate this behaviour by only returning the pipe as writable
if at least 4K space is left in the buffer.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/cygwin/select.cc | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 725aab90c7a6..db52ffcccf8e 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -591,7 +591,7 @@ pipe_data_available (int fd, fhandler_base *fh, HANDLE h, bool writing)
{
DWORD nbytes_in_pipe;
if (!writing && PeekNamedPipe (h, NULL, 0, NULL, &nbytes_in_pipe, NULL))
- return nbytes_in_pipe > 0;
+ return nbytes_in_pipe;
return -1;
}
@@ -609,7 +609,7 @@ pipe_data_available (int fd, fhandler_base *fh, HANDLE h, bool writing)
access on the write end. */
select_printf ("fd %d, %s, NtQueryInformationFile failed, status %y",
fd, fh->get_name (), status);
- return writing ? 1 : -1;
+ return writing ? PIPE_BUF : -1;
}
if (writing)
{
@@ -644,14 +644,14 @@ pipe_data_available (int fd, fhandler_base *fh, HANDLE h, bool writing)
if (!query_hdl)
query_hdl = ((fhandler_pipe *) fh)->temporary_query_hdl ();
if (!query_hdl)
- return 1; /* We cannot know actual write pipe space. */
+ return PIPE_BUF; /* We cannot know actual write pipe space. */
DWORD nbytes_in_pipe;
BOOL res =
PeekNamedPipe (query_hdl, NULL, 0, NULL, &nbytes_in_pipe, NULL);
if (!((fhandler_pipe *) fh)->get_query_handle ())
CloseHandle (query_hdl); /* Close temporary query_hdl */
if (!res)
- return 1;
+ return PIPE_BUF; /* We cannot know actual write pipe space. */
fpli.WriteQuotaAvailable = fpli.InboundQuota - nbytes_in_pipe;
}
if (fpli.WriteQuotaAvailable > 0)
@@ -659,7 +659,7 @@ pipe_data_available (int fd, fhandler_base *fh, HANDLE h, bool writing)
paranoid_printf ("fd %d, %s, write: size %u, avail %u", fd,
fh->get_name (), fpli.InboundQuota,
fpli.WriteQuotaAvailable);
- return 1;
+ return fpli.WriteQuotaAvailable;
}
/* TODO: Buffer really full or non-Cygwin reader? */
}
@@ -667,7 +667,7 @@ pipe_data_available (int fd, fhandler_base *fh, HANDLE h, bool writing)
{
paranoid_printf ("fd %d, %s, read avail %u", fd, fh->get_name (),
fpli.ReadDataAvailable);
- return 1;
+ return fpli.ReadDataAvailable;
}
if (fpli.NamedPipeState & FILE_PIPE_CLOSING_STATE)
return -1;
@@ -761,7 +761,7 @@ out:
}
int n = pipe_data_available (s->fd, fh, h, true);
select_printf ("write: %s, n %d", fh->get_name (), n);
- gotone += s->write_ready = n;
+ gotone += s->write_ready = (n >= PIPE_BUF);
if (n < 0 && s->except_selected)
gotone += s->except_ready = true;
}
@@ -974,7 +974,7 @@ out:
{
int n = pipe_data_available (s->fd, fh, fh->get_handle (), true);
select_printf ("write: %s, n %d", fh->get_name (), n);
- gotone += s->write_ready = n;
+ gotone += s->write_ready = (n >= PIPE_BUF);
if (n < 0 && s->except_selected)
gotone += s->except_ready = true;
}
@@ -1400,7 +1400,7 @@ out:
{
int n = pipe_data_available (s->fd, fh, h, true);
select_printf ("write: %s, n %d", fh->get_name (), n);
- gotone += s->write_ready = n;
+ gotone += s->write_ready = (n >= PIPE_BUF);
if (n < 0 && s->except_selected)
gotone += s->except_ready = true;
}
More information about the Cygwin-cvs
mailing list