summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fhandler.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2012-01-31 23:52:52 +0000
committerChristopher Faylor <me@cgf.cx>2012-01-31 23:52:52 +0000
commitd3cb1dffefe964ae9bfd4a47a8075c2b3ecfd27f (patch)
treefb72d9dadd6a25249cb61e95d0f37ede32cd8510 /winsup/cygwin/fhandler.cc
parent37fbb8a7417433a309e3dbe5af7315726fb3a17a (diff)
downloadcygnal-d3cb1dffefe964ae9bfd4a47a8075c2b3ecfd27f.tar.gz
cygnal-d3cb1dffefe964ae9bfd4a47a8075c2b3ecfd27f.tar.bz2
cygnal-d3cb1dffefe964ae9bfd4a47a8075c2b3ecfd27f.zip
* syscalls.cc (dup3): Fix debug typo.
* fhandler.cc (flush_async_io): Assume only called for writer. Call GetOverlappedResult directly rather than kluding call to has_ongoing_io. (fhandler_base_overlapped::close): Only start flush thread when closing write handle. Only cancel I/O when reading.
Diffstat (limited to 'winsup/cygwin/fhandler.cc')
-rw-r--r--winsup/cygwin/fhandler.cc15
1 files changed, 8 insertions, 7 deletions
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 9c229933e..0997c9abb 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -1156,11 +1156,10 @@ DWORD WINAPI
flush_async_io (void *arg)
{
fhandler_base_overlapped *fh = (fhandler_base_overlapped *) arg;
- debug_only_printf ("waiting for %s I/O for %s",
- (fh->get_access () & GENERIC_WRITE) ? "write" : "read",
- fh->get_name ());
- SetEvent (fh->get_overlapped ()->hEvent); /* force has_ongoing_io to block */
- bool res = fh->has_ongoing_io ();
+ debug_only_printf ("waiting for write I/O for %s", fh->get_name ());
+ DWORD nbytes;
+ bool res = GetOverlappedResult (fh->get_output_handle (),
+ fh->get_overlapped (), &nbytes, true);
debug_printf ("finished waiting for I/O from %s, res %d", fh->get_name (),
res);
fh->close ();
@@ -1210,9 +1209,10 @@ int
fhandler_base_overlapped::close ()
{
int res;
+ int writer = (get_access () & GENERIC_WRITE);
/* Need to treat non-blocking I/O specially because Windows appears to
be brain-dead */
- if (is_nonblocking () && has_ongoing_io ())
+ if (writer && is_nonblocking () && has_ongoing_io ())
{
clone (HEAP_3_FHANDLER)->check_later ();
res = 0;
@@ -1221,7 +1221,8 @@ fhandler_base_overlapped::close ()
{
/* Cancelling seems to be necessary for cases where a reader is
still executing when a signal handler performs a close. */
- CancelIo (get_io_handle ());
+ if (!writer)
+ CancelIo (get_io_handle ());
destroy_overlapped ();
res = fhandler_base::close ();
}