From 8b46f03c8da80400de53027270a23fbcfa472730 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 26 Jun 2006 12:12:11 +0000 Subject: Revert patches from 2005-10-22 and 2006-06-14 to use event driven accept and connect back to using select: * fhandler.h (class fhandler_socket): Remove accept_mtx. * fhandler_socket.cc (fhandler_socket::fhandler_socket): Drop initializing accept_mtx. (fhandler_socket::accept): Drop event handling. (fhandler_socket.cc (fhandler_socket::connect): Ditto. (fhandler_socket::dup): Drop accept_mtx handling. (fhandler_socket::listen): Ditto. (fhandler_socket::prepare): Ditto. (fhandler_socket::release): Ditto. (fhandler_socket::close): Ditto. * net.cc (cygwin_accept): Revert to calling cygwin_select to implement interuptible accept. (cygwin_connect): Ditto for connect. --- winsup/cygwin/net.cc | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) (limited to 'winsup/cygwin/net.cc') diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 3bc92d2be..b8213081f 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -814,7 +814,56 @@ cygwin_connect (int fd, const struct sockaddr *name, int namelen) if (efault.faulted (EFAULT) || !fh) res = -1; else - res = fh->connect (name, namelen); + { + bool was_blocking = false; + if (!fh->is_nonblocking ()) + { + int nonblocking = 1; + fh->ioctl (FIONBIO, &nonblocking); + was_blocking = true; + } + res = fh->connect (name, namelen); + if (was_blocking) + { + if (res == -1 && get_errno () == EINPROGRESS) + { + size_t fds_size = howmany (fd + 1, NFDBITS) * sizeof (fd_mask); + fd_set *write_fds = (fd_set *) alloca (fds_size); + fd_set *except_fds = (fd_set *) alloca (fds_size); + memset (write_fds, 0, fds_size); + memset (except_fds, 0, fds_size); + FD_SET (fd, write_fds); + FD_SET (fd, except_fds); + res = cygwin_select (fd + 1, NULL, write_fds, except_fds, NULL); + if (res > 0 && FD_ISSET (fd, except_fds)) + { + res = -1; + for (;;) + { + int err; + int len = sizeof err; + cygwin_getsockopt (fd, SOL_SOCKET, SO_ERROR, + (void *) &err, &len); + if (err) + { + set_errno (err); + break; + } + low_priority_sleep (0); + } + } + else if (res > 0) + res = 0; + else + { + WSASetLastError (WSAEINPROGRESS); + set_winsock_errno (); + } + } + int nonblocking = 0; + fh->ioctl (FIONBIO, &nonblocking); + } + } syscall_printf ("%d = connect (%d, %p, %d)", res, fd, name, namelen); @@ -948,7 +997,19 @@ cygwin_accept (int fd, struct sockaddr *peer, int *len) if (efault.faulted (EFAULT) || !fh) res = -1; else - res = fh->accept (peer, len); + { + if (!fh->is_nonblocking ()) + { + size_t fds_size = howmany (fd + 1, NFDBITS) * sizeof (fd_mask); + fd_set *read_fds = (fd_set *) alloca (fds_size); + memset (read_fds, 0, fds_size); + FD_SET (fd, read_fds); + res = cygwin_select (fd + 1, read_fds, NULL, NULL, NULL); + if (res == -1) + return -1; + } + res = fh->accept (peer, len); + } syscall_printf ("%d = accept (%d, %p, %p)", res, fd, peer, len); return res; -- cgit v1.2.3