Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2009-06-28 23:23:13 +0400
committerChristopher Faylor <me@cgf.cx>2009-06-28 23:23:13 +0400
commitc81ceaefec39454f5f76f91be2885d577a668527 (patch)
treecb9c49bf0597eb5d22275fdd8a7f955b7b7f6eee /winsup/cygwin/fhandler.cc
parent91000b5d66688fe62926edc72a00f00c9cda30ab (diff)
* fhandler.h (fhandler_base::has_ongoing_io): Declare new function.
* fhandler.cc (fhandler_base::has_ongoing_io): Define new function. (fhandler_base::read_overlapped): Use has_ongoing_io to avoid writing when handle has not completed last I/O. (fhandler_base::write_overlapped): Ditto. * select.cc (peek_pipe): Be more careful about accessing hEvent field from get_overlapped().
Diffstat (limited to 'winsup/cygwin/fhandler.cc')
-rw-r--r--winsup/cygwin/fhandler.cc44
1 files changed, 33 insertions, 11 deletions
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index da656ce28..650cca9e9 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -1763,33 +1763,55 @@ fhandler_base::wait_overlapped (bool inres, bool writing, DWORD *bytes, DWORD le
return res;
}
-void
+bool __stdcall
+fhandler_base::has_ongoing_io ()
+{
+ if (get_overlapped () && get_overlapped ()->hEvent
+ && WaitForSingleObject (get_overlapped ()->hEvent, 0) != WAIT_OBJECT_0)
+ {
+ set_errno (EAGAIN);
+ return true;
+ }
+ return false;
+}
+
+void __stdcall
fhandler_base::read_overlapped (void *ptr, size_t& len)
{
- DWORD bytes_read;
+ DWORD nbytes;
while (1)
{
- bool res = ReadFile (get_handle (), ptr, len, &bytes_read,
+ if (has_ongoing_io ())
+ {
+ nbytes = (DWORD) -1;
+ break;
+ }
+ bool res = ReadFile (get_handle (), ptr, len, &nbytes,
get_overlapped ());
- int wres = wait_overlapped (res, false, &bytes_read);
+ int wres = wait_overlapped (res, false, &nbytes);
if (wres || !_my_tls.call_signal_handler ())
break;
}
- len = (size_t) bytes_read;
+ len = (size_t) nbytes;
}
-int
+int __stdcall
fhandler_base::write_overlapped (const void *ptr, size_t len)
{
- DWORD bytes_written;
+ DWORD nbytes;
while (1)
{
- bool res = WriteFile (get_output_handle (), ptr, len, &bytes_written,
+ if (has_ongoing_io ())
+ {
+ nbytes = (DWORD) -1;
+ break;
+ }
+ bool res = WriteFile (get_output_handle (), ptr, len, &nbytes,
get_overlapped ());
- int wres = wait_overlapped (res, true, &bytes_written, (size_t) len);
+ int wres = wait_overlapped (res, true, &nbytes, (size_t) len);
if (wres || !_my_tls.call_signal_handler ())
break;
}
- debug_printf ("returning %u", bytes_written);
- return bytes_written;
+ debug_printf ("returning %u", nbytes);
+ return nbytes;
}