* errno.cc (errmap): Add mapping for ERROR_IO_INCOMPLETE.

* fhandler.cc (fhandler_base::fcntl): Fix comment.
(fhandler_base::wait_overlapped): Accept an optional len parameter.  Use the
len parameter when WriteFile fails with ERROR_IO_PENDING.  Make debug output
less alarming.
(fhandler_base::write_overlapped): Pass len to wait_overlapped.
* fhandler.h (fhandler_base::wait_overlapped): Add an optional argument
denoting the number of characters intended to be written.
* fhandler_tty.cc (fhandler_pty_master::close): Don't close archetype handles
when cygwin is still initializing since the handles aren't actually opened at
that point.
This commit is contained in:
Christopher Faylor 2009-06-14 23:42:09 +00:00
parent 313c719cb8
commit fee56469d4
5 changed files with 47 additions and 16 deletions

View File

@ -1,3 +1,18 @@
2009-06-14 Christopher Faylor <me+cygwin@cgf.cx>
* errno.cc (errmap): Add mapping for ERROR_IO_INCOMPLETE.
* fhandler.cc (fhandler_base::fcntl): Fix comment.
(fhandler_base::wait_overlapped): Accept an optional len parameter.
Use the len parameter when WriteFile fails with ERROR_IO_PENDING. Make
debug output less alarming.
(fhandler_base::write_overlapped): Pass len to wait_overlapped.
* fhandler.h (fhandler_base::wait_overlapped): Add an optional argument
denoting the number of characters intended to be written.
* fhandler_tty.cc (fhandler_pty_master::close): Don't close archetype
handles when cygwin is still initializing since the handles aren't
actually opened at that point.
2009-06-14 Corinna Vinschen <corinna@vinschen.de>
* localtime.cc (time2): Take another stab at fixing a compiler warning.

View File

@ -139,6 +139,7 @@ static NO_COPY struct
X (WRITE_PROTECT, EROFS),
X (SEEK, EINVAL),
X (SECTOR_NOT_FOUND, EINVAL),
X (IO_INCOMPLETE, EAGAIN),
{ 0, NULL, 0}
};

View File

@ -1185,12 +1185,10 @@ int fhandler_base::fcntl (int cmd, void *arg)
break;
case F_SETFL:
{
/*
* Only O_APPEND, O_ASYNC and O_NONBLOCK/O_NDELAY are allowed.
* Each other flag will be ignored.
* Since O_ASYNC isn't defined in fcntl.h it's currently
* ignored as well.
*/
/* Only O_APPEND, O_ASYNC and O_NONBLOCK/O_NDELAY are allowed.
Each other flag will be ignored.
Since O_ASYNC isn't defined in fcntl.h it's currently
ignored as well. */
const int allowed_flags = O_APPEND | O_NONBLOCK_MASK;
int new_flags = (int) arg & allowed_flags;
/* Carefully test for the O_NONBLOCK or deprecated OLD_O_NDELAY flag.
@ -1676,7 +1674,7 @@ fhandler_base::destroy_overlapped ()
}
int
fhandler_base::wait_overlapped (bool inres, bool writing, DWORD *bytes)
fhandler_base::wait_overlapped (bool inres, bool writing, DWORD *bytes, DWORD len)
{
if (!get_overlapped ())
return inres;
@ -1686,8 +1684,22 @@ fhandler_base::wait_overlapped (bool inres, bool writing, DWORD *bytes)
DWORD err;
if (is_nonblocking ())
{
err = GetLastError ();
res = inres;
if (inres || GetLastError () == ERROR_IO_PENDING)
{
if (writing && !inres)
*bytes = len; /* This really isn't true but it seems like
this is a corner-case for linux's
non-blocking I/O implementation. How can
you know how many bytes were written until
the I/O operation really completes? */
res = 1;
err = 0;
}
else
{
res = 0;
err = GetLastError ();
}
}
else if (inres || ((err = GetLastError ()) == ERROR_IO_PENDING))
{
@ -1719,7 +1731,7 @@ fhandler_base::wait_overlapped (bool inres, bool writing, DWORD *bytes)
else if (!wores)
{
err = GetLastError ();
debug_printf ("general error");
debug_printf ("GetOverLappedResult failed");
}
else
{
@ -1779,7 +1791,7 @@ fhandler_base::write_overlapped (const void *ptr, size_t len)
{
bool res = WriteFile (get_output_handle (), ptr, len, &bytes_written,
get_overlapped ());
int wres = wait_overlapped (res, true, &bytes_written);
int wres = wait_overlapped (res, true, &bytes_written, (size_t) len);
if (wres || !_my_tls.call_signal_handler ())
break;
}

View File

@ -143,7 +143,7 @@ class fhandler_base
void del_my_locks (bool);
HANDLE read_state;
int wait_overlapped (bool, bool, DWORD *) __attribute__ ((regparm (3)));
int wait_overlapped (bool, bool, DWORD *, DWORD = 0) __attribute__ ((regparm (3)));
bool setup_overlapped (bool doit = true) __attribute__ ((regparm (2)));
void destroy_overlapped () __attribute__ ((regparm (1)));

View File

@ -1184,10 +1184,13 @@ fhandler_pty_master::close ()
fhandler_tty_master *arch = (fhandler_tty_master *) archetype;
termios_printf ("closing from_master(%p)/to_master(%p) since we own them(%d)",
arch->from_master, arch->to_master, arch->dwProcessId);
if (!ForceCloseHandle (arch->from_master))
termios_printf ("error closing from_master %p, %E", arch->from_master);
if (!ForceCloseHandle (arch->to_master))
termios_printf ("error closing from_master %p, %E", arch->to_master);
if (cygwin_finished_initializing)
{
if (!ForceCloseHandle (arch->from_master))
termios_printf ("error closing from_master %p, %E", arch->from_master);
if (!ForceCloseHandle (arch->to_master))
termios_printf ("error closing from_master %p, %E", arch->to_master);
}
fhandler_tty_common::close ();
if (hExeced || get_ttyp ()->master_pid != myself->pid)