Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2006-06-26 16:12:11 +0400
committerCorinna Vinschen <corinna@vinschen.de>2006-06-26 16:12:11 +0400
commit8b46f03c8da80400de53027270a23fbcfa472730 (patch)
tree4fa9ff6c61bff9cbb054442f21b6afdca4b68483 /winsup/cygwin/net.cc
parent50d838a468eae05cb2bcceb8272dcbac4e6cff43 (diff)
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.
Diffstat (limited to 'winsup/cygwin/net.cc')
-rw-r--r--winsup/cygwin/net.cc65
1 files changed, 63 insertions, 2 deletions
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;