From 05901e6aee8af35b4d4d24bdefe2d307a86398aa Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Mon, 21 Feb 2011 03:18:30 +0000 Subject: [PATCH] * fhandler.cc (fhandler_base_overlapped::close): Finish any pending I/O before closing. (fhandler_base_overlapped::wait_overlapped): Defensively zero bytes read. Add more info to debugging output. --- winsup/cygwin/ChangeLog | 7 +++++++ winsup/cygwin/fhandler.cc | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 80e8e401f..c5fa0661a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2011-02-20 Christopher Faylor + + * fhandler.cc (fhandler_base_overlapped::close): Finish any pending I/O + before closing. + (fhandler_base_overlapped::wait_overlapped): Defensively zero bytes + read. Add more info to debugging output. + 2011-02-18 Christopher Faylor * dcrt0.cc (dll_crt0_1): Add a CYGHEAP_DEBUG conditional for debugging diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 2ff6827be..cea9c1bb0 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -1046,6 +1046,12 @@ fhandler_base::close () int fhandler_base_overlapped::close () { + if (is_nonblocking () && io_pending) + { + DWORD bytes; + set_nonblocking (false); + wait_overlapped (1, !!(get_access () & GENERIC_WRITE), &bytes); + } destroy_overlapped (); return fhandler_base::close (); } @@ -1749,6 +1755,7 @@ fhandler_base_overlapped::wait_overlapped (bool inres, bool writing, DWORD *byte DWORD wfres = WaitForMultipleObjects (n, w4, false, INFINITE); if (wfres != WAIT_OBJECT_0) CancelIo (h); + *bytes = 0; BOOL wores = GetOverlappedResult (h, get_overlapped (), bytes, false); bool signalled = !wores && (wfres == WAIT_OBJECT_0 + 1); if (signalled) @@ -1762,7 +1769,7 @@ fhandler_base_overlapped::wait_overlapped (bool inres, bool writing, DWORD *byte else if (!wores) { err = GetLastError (); - debug_printf ("GetOverLappedResult failed"); + debug_printf ("GetOverLappedResult failed, bytes %u", *bytes); } else {