summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fhandler.cc
diff options
context:
space:
mode:
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;
}