This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH 12/14] Cygwin: FIFO: start the listen_client thread when duping a reader
- From: Ken Brown <kbrown at cornell dot edu>
- To: "cygwin-patches at cygwin dot com" <cygwin-patches at cygwin dot com>
- Date: Sun, 14 Apr 2019 19:16:03 +0000
- Subject: [PATCH 12/14] Cygwin: FIFO: start the listen_client thread when duping a reader
- References: <20190414191543.3218-1-kbrown@cornell.edu>
Otherwise it doesn't get started until the dup'd fd tries to read,
which delays client connections.
---
winsup/cygwin/fhandler_fifo.cc | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index a3ecbeb4a..fe4c67bdf 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -853,19 +853,20 @@ fhandler_fifo::close ()
int
fhandler_fifo::dup (fhandler_base *child, int flags)
{
+ int ret = -1;
+ fhandler_fifo *fhf = NULL;
+
if (fhandler_base::dup (child, flags))
- {
- __seterrno ();
- return -1;
- }
- fhandler_fifo *fhf = (fhandler_fifo *) child;
+ goto out;
+
+ fhf = (fhandler_fifo *) child;
if (!DuplicateHandle (GetCurrentProcess (), read_ready,
GetCurrentProcess (), &fhf->read_ready,
0, true, DUPLICATE_SAME_ACCESS))
{
fhf->close ();
__seterrno ();
- return -1;
+ goto out;
}
if (!DuplicateHandle (GetCurrentProcess (), write_ready,
GetCurrentProcess (), &fhf->write_ready,
@@ -874,7 +875,7 @@ fhandler_fifo::dup (fhandler_base *child, int flags)
CloseHandle (fhf->read_ready);
fhf->close ();
__seterrno ();
- return -1;
+ goto out;
}
for (int i = 0; i < nhandlers; i++)
{
@@ -895,13 +896,16 @@ fhandler_fifo::dup (fhandler_base *child, int flags)
CloseHandle (fhf->write_ready);
fhf->close ();
__seterrno ();
- return -1;
+ goto out;
}
}
fhf->listen_client_thr = NULL;
fhf->lct_termination_evt = NULL;
fhf->fifo_client_unlock ();
- return 0;
+ if (!reader || fhf->listen_client ())
+ ret = 0;
+out:
+ return ret;
}
void
--
2.17.0