OSDN Git Service

* fhandler.cc (fhandler_base::is_nonblocking): New method.
authorcorinna <corinna>
Wed, 15 Aug 2001 07:49:14 +0000 (07:49 +0000)
committercorinna <corinna>
Wed, 15 Aug 2001 07:49:14 +0000 (07:49 +0000)
        (fhandler_base::set_nonblocking): Ditto.
        * fhandler.h (fhandler_base): Declare new methods `is_nonblocking' and
        `set_nonblocking'.
        * fhandler_socket.cc (fhandler_socket::ioctl): Use `set_nonblocking'.
        * fhandler_tty.cc (fhandler_pty_master::process_slave_output):
        Use `is_nonblocking'.
        (fhandler_tty_slave::read): Ditto.
        (fhandler_tty_slave::ioctl): Use `set_nonblocking'.
        (fhandler_pty_master::ioctl): Ditto.
        * net.cc (cygwin_sendto): Fallback to winsock 1 functionality
        in case of nonblocking IO.
        (cygwin_recvfrom): Ditto.
        (cygwin_recv): Ditto.
        (cygwin_send): Ditto.
        * syscalls.cc (_read): Use `is_nonblocking'.

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler.cc
winsup/cygwin/fhandler.h
winsup/cygwin/fhandler_socket.cc
winsup/cygwin/fhandler_tty.cc
winsup/cygwin/net.cc
winsup/cygwin/syscalls.cc

index 0c9e9e7..16874fe 100644 (file)
@@ -1,3 +1,22 @@
+Wed Aug 15  9:42:00 2001  Corinna Vinschen <corinna@vinschen.de>
+
+       * fhandler.cc (fhandler_base::is_nonblocking): New method.
+       (fhandler_base::set_nonblocking): Ditto.
+       * fhandler.h (fhandler_base): Declare new methods `is_nonblocking' and
+       `set_nonblocking'.
+       * fhandler_socket.cc (fhandler_socket::ioctl): Use `set_nonblocking'.
+       * fhandler_tty.cc (fhandler_pty_master::process_slave_output):
+       Use `is_nonblocking'.
+       (fhandler_tty_slave::read): Ditto.
+       (fhandler_tty_slave::ioctl): Use `set_nonblocking'.
+       (fhandler_pty_master::ioctl): Ditto.
+       * net.cc (cygwin_sendto): Fallback to winsock 1 functionality
+       in case of nonblocking IO.
+       (cygwin_recvfrom): Ditto.
+       (cygwin_recv): Ditto.
+       (cygwin_send): Ditto.
+       * syscalls.cc (_read): Use `is_nonblocking'.
+
 Tue Aug 14 11:05:26 2001  Christopher Faylor <cgf@cygnus.com>
 
        * include/cygwin/version.h: Bump API version.
index c4af734..86c6b4d 100644 (file)
@@ -1572,3 +1572,17 @@ fhandler_base::fixup_after_fork (HANDLE parent)
   debug_printf ("inheriting '%s' from parent", get_name ());
   fork_fixup (parent, io_handle, "io_handle");
 }
+
+int
+fhandler_base::is_nonblocking ()
+{
+  return (openflags & O_NONBLOCK_MASK) != 0;
+}
+
+void
+fhandler_base::set_nonblocking (int yes)
+{
+  int current = openflags & O_NONBLOCK_MASK;
+  int new_flags = yes ? (!current ? O_NONBLOCK : current) : 0;
+  openflags = (openflags & ~O_NONBLOCK_MASK) | new_flags;
+}
index a46f7d9..dd1df29 100644 (file)
@@ -207,6 +207,9 @@ public:
   int get_flags () { return openflags; }
   void set_flags (int x) { openflags = x; }
 
+  int is_nonblocking ();
+  void set_nonblocking (int yes);
+
   int get_w_binary () { return FHISSETF (WBINARY); }
   int get_r_binary () { return FHISSETF (RBINARY); }
 
index 7c1be07..9e63489 100644 (file)
@@ -406,9 +406,7 @@ fhandler_socket::ioctl (unsigned int cmd, void *p)
          if (*(int *) p && get_async ())
            WSAAsyncSelect (get_socket (), gethwnd (), WM_ASYNCIO, ASYNC_MASK);
 
-         int current = get_flags () & O_NONBLOCK_MASK;
-         int new_flags = *(int *) p ? (!current ? O_NONBLOCK : current) : 0;
-         set_flags ((get_flags () & ~O_NONBLOCK_MASK) | new_flags);
+         set_nonblocking (*(int *) p);
        }
       break;
     }
index 942f31d..5d51ca0 100644 (file)
@@ -25,8 +25,6 @@ details. */
 #include "pinfo.h"
 #include "cygheap.h"
 #include "shared_info.h"
-#include "cygwin/version.h"
-#include "perprocess.h"
 
 /* Tty master stuff */
 
@@ -297,7 +295,7 @@ fhandler_pty_master::process_slave_output (char *buf, size_t len, int pktmode_on
                break;
              if (hit_eof ())
                goto out;
-             if (n == 0 && (get_flags () & O_NONBLOCK_MASK) != 0)
+             if (n == 0 && is_nonblocking ())
                {
                  set_errno (EAGAIN);
                  rc = -1;
@@ -748,8 +746,7 @@ fhandler_tty_slave::read (void *ptr, size_t len)
          termios_printf ("saw EOF");
          break;
        }
-      if (get_ttyp ()->ti.c_lflag & ICANON ||
-         get_flags () & O_NONBLOCK_MASK)
+      if (get_ttyp ()->ti.c_lflag & ICANON || is_nonblocking ())
        break;
       if (totalread >= vmin && (vmin > 0 || totalread > 0))
        break;
@@ -915,11 +912,7 @@ fhandler_tty_slave::ioctl (unsigned int cmd, void *arg)
     case TIOCSWINSZ:
       break;
     case FIONBIO:
-      {
-       int current = get_flags () & O_NONBLOCK_MASK;
-       int new_flags = *(int *) arg ? (!current ? O_NONBLOCK : current) : 0;
-       set_flags ((get_flags () & ~O_NONBLOCK_MASK) | new_flags);
-      }
+      set_nonblocking (*(int *) arg);
       goto out;
     default:
       set_errno (EINVAL);
@@ -1099,11 +1092,7 @@ fhandler_pty_master::ioctl (unsigned int cmd, void *arg)
        _kill (-get_ttyp ()->getpgid (), SIGWINCH);
        break;
       case FIONBIO:
-       {
-         int current = get_flags () & O_NONBLOCK_MASK;
-         int new_flags = *(int *) arg ? (!current ? O_NONBLOCK : current) : 0;
-         set_flags ((get_flags () & ~O_NONBLOCK_MASK) | new_flags);
-       }
+       set_nonblocking (*(int *) arg);
        break;
       default:
        set_errno (EINVAL);
index be68f42..db7a949 100644 (file)
@@ -25,7 +25,6 @@ details. */
 #define USE_SYS_TYPES_FD_SET
 #include <winsock2.h>
 #include "cygerrno.h"
-#include "perprocess.h"
 #include "security.h"
 #include "fhandler.h"
 #include "path.h"
@@ -512,7 +511,7 @@ cygwin_sendto (int fd,
   if (get_inet_addr (to, tolen, &sin, &tolen) == 0)
     return -1;
 
-  if (!(ovr = wsock_evt.prepare ()))
+  if (h->is_nonblocking () || !(ovr = wsock_evt.prepare ()))
     {
       debug_printf ("Fallback to winsock 1 sendto call");
       if ((res = sendto (h->get_socket (), (const char *) buf, len, flags,
@@ -558,7 +557,7 @@ cygwin_recvfrom (int fd,
   fhandler_socket *h = (fhandler_socket *) cygheap->fdtab[fd];
   sigframe thisframe (mainthread);
 
-  if (!(ovr = wsock_evt.prepare ()))
+  if (h->is_nonblocking () ||!(ovr = wsock_evt.prepare ()))
     {
       debug_printf ("Fallback to winsock 1 recvfrom call");
       if ((res = recvfrom (h->get_socket (), buf, len, flags, from, fromlen))
@@ -1208,7 +1207,7 @@ cygwin_recv (int fd, void *buf, int len, unsigned int flags)
   fhandler_socket *h = (fhandler_socket *) cygheap->fdtab[fd];
   sigframe thisframe (mainthread);
 
-  if (!(ovr = wsock_evt.prepare ()))
+  if (h->is_nonblocking () || !(ovr = wsock_evt.prepare ()))
     {
       debug_printf ("Fallback to winsock 1 recv call");
       if ((res = recv (h->get_socket (), (char *) buf, len, flags))
@@ -1249,7 +1248,7 @@ cygwin_send (int fd, const void *buf, int len, unsigned int flags)
   fhandler_socket *h = (fhandler_socket *) cygheap->fdtab[fd];
   sigframe thisframe (mainthread);
 
-  if (!(ovr = wsock_evt.prepare ()))
+  if (h->is_nonblocking () || !(ovr = wsock_evt.prepare ()))
     {
       debug_printf ("Fallback to winsock 1 send call");
       if ((res = send (h->get_socket (), (const char *) buf, len, flags))
index f3fecf1..9fbd7f8 100644 (file)
@@ -271,7 +271,7 @@ _read (int fd, void *ptr, size_t len)
 
       // set_sig_errno (0);
       fh = cygheap->fdtab[fd];
-      DWORD wait = (fh->get_flags () & O_NONBLOCK_MASK) ? 0 : INFINITE;
+      DWORD wait = fh->is_nonblocking () ? 0 : INFINITE;
 
       /* Could block, so let user know we at least got here.  */
       syscall_printf ("read (%d, %p, %d) %sblocking, sigcatchers %d", fd, ptr, len, wait ? "" : "non", sigcatchers);