diff options
author | Christopher Faylor <me@cgf.cx> | 2009-06-28 19:23:13 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2009-06-28 19:23:13 +0000 |
commit | c81ceaefec39454f5f76f91be2885d577a668527 (patch) | |
tree | cb9c49bf0597eb5d22275fdd8a7f955b7b7f6eee | |
parent | 91000b5d66688fe62926edc72a00f00c9cda30ab (diff) | |
download | newlib-c81ceaefec39454f5f76f91be2885d577a668527.zip newlib-c81ceaefec39454f5f76f91be2885d577a668527.tar.gz newlib-c81ceaefec39454f5f76f91be2885d577a668527.tar.bz2 |
* 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().
-rw-r--r-- | winsup/cygwin/ChangeLog | 18 | ||||
-rw-r--r-- | winsup/cygwin/fhandler.cc | 44 | ||||
-rw-r--r-- | winsup/cygwin/fhandler.h | 1 | ||||
-rw-r--r-- | winsup/cygwin/select.cc | 2 |
4 files changed, 53 insertions, 12 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index b5197b6..24a66be 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,10 +1,28 @@ 2009-06-28 Christopher Faylor <me+cygwin@cgf.cx> + * 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(). + +2009-06-28 Christopher Faylor <me+cygwin@cgf.cx> + * gendef (cleanup): Rename from 'nocr'. Remove comments and trailing spaces. * cygwin.din: Add long-needed comment describing what dll_crt0__FP11per_process demangles to. + * select.cc (peek_pipe): Flag handle as not ready for write if event is + not signalled. + * fhandler.cc (fhandler_base::setup_overlapped): Establish event as + already signalled. + (fhandler_base::wait_overlapped): Don't reset event after we've + successfully waited. MSDN documentation says that this happens + automatically after a WriteFileEx/ReadFileEx. + 2009-06-26 Corinna Vinschen <corinna@vinschen.de> * wincap.h (wincaps::has_broken_alloc_console): New element. diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index da656ce..650cca9 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; } diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 1efd8fd..a4cc50f 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -302,6 +302,7 @@ class fhandler_base virtual char const *ttyname () { return get_name (); } virtual void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3))); virtual void __stdcall read_overlapped (void *ptr, size_t& len) __attribute__ ((regparm (3))); + virtual bool __stdcall has_ongoing_io () __attribute__ ((regparm (1))); virtual int write (const void *ptr, size_t len); virtual int __stdcall write_overlapped (const void *ptr, size_t len); virtual ssize_t readv (const struct iovec *, int iovcnt, ssize_t tot = -1); diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index c3dc005..26cb3b4 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -513,7 +513,7 @@ out: else if (fh->get_device () == FH_PIPER) select_printf ("%s, select for write on read end of pipe", fh->get_name ()); - else if (fh->get_overlapped ()->hEvent + else if (fh->get_overlapped () && fh->get_overlapped ()->hEvent && WaitForSingleObject (fh->get_overlapped ()->hEvent, 0) != WAIT_OBJECT_0) s->write_ready = false; |