diff options
author | Christopher Faylor <me@cgf.cx> | 2009-06-15 03:42:09 +0400 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2009-06-15 03:42:09 +0400 |
commit | fee56469d473166006476374717805e0901bda0f (patch) | |
tree | 28aa717f4264869399392b91b4218ac47f580597 | |
parent | 313c719cb83191e8ea0072edba4d9d399737eac4 (diff) |
* 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.
-rw-r--r-- | winsup/cygwin/ChangeLog | 15 | ||||
-rw-r--r-- | winsup/cygwin/errno.cc | 1 | ||||
-rw-r--r-- | winsup/cygwin/fhandler.cc | 34 | ||||
-rw-r--r-- | winsup/cygwin/fhandler.h | 2 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_tty.cc | 11 |
5 files changed, 47 insertions, 16 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 8a4fccd6c..b41486066 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -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. diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc index fc14dcbe3..617970a72 100644 --- a/winsup/cygwin/errno.cc +++ b/winsup/cygwin/errno.cc @@ -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} }; diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 0d499ba9c..2e909fbd1 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -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; } diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 4731c3089..1efd8fd58 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -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))); diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 994d356c0..979ffc3d8 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -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) |