* 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().
This commit is contained in:
Christopher Faylor 2009-06-28 19:23:13 +00:00
parent 91000b5d66
commit c81ceaefec
4 changed files with 60 additions and 19 deletions

View File

@ -1,3 +1,13 @@
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
@ -5,6 +15,14 @@
* 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.

View File

@ -1763,33 +1763,55 @@ fhandler_base::wait_overlapped (bool inres, bool writing, DWORD *bytes, DWORD le
return res;
}
void
fhandler_base::read_overlapped (void *ptr, size_t& len)
bool __stdcall
fhandler_base::has_ongoing_io ()
{
DWORD bytes_read;
while (1)
if (get_overlapped () && get_overlapped ()->hEvent
&& WaitForSingleObject (get_overlapped ()->hEvent, 0) != WAIT_OBJECT_0)
{
bool res = ReadFile (get_handle (), ptr, len, &bytes_read,
get_overlapped ());
int wres = wait_overlapped (res, false, &bytes_read);
if (wres || !_my_tls.call_signal_handler ())
break;
set_errno (EAGAIN);
return true;
}
len = (size_t) bytes_read;
return false;
}
int
fhandler_base::write_overlapped (const void *ptr, size_t len)
void __stdcall
fhandler_base::read_overlapped (void *ptr, size_t& len)
{
DWORD bytes_written;
DWORD nbytes;
while (1)
{
bool res = WriteFile (get_output_handle (), ptr, len, &bytes_written,
get_overlapped ());
int wres = wait_overlapped (res, true, &bytes_written, (size_t) len);
if (has_ongoing_io ())
{
nbytes = (DWORD) -1;
break;
}
bool res = ReadFile (get_handle (), ptr, len, &nbytes,
get_overlapped ());
int wres = wait_overlapped (res, false, &nbytes);
if (wres || !_my_tls.call_signal_handler ())
break;
}
debug_printf ("returning %u", bytes_written);
return bytes_written;
len = (size_t) nbytes;
}
int __stdcall
fhandler_base::write_overlapped (const void *ptr, size_t len)
{
DWORD nbytes;
while (1)
{
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, &nbytes, (size_t) len);
if (wres || !_my_tls.call_signal_handler ())
break;
}
debug_printf ("returning %u", nbytes);
return nbytes;
}

View File

@ -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);

View File

@ -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;