Cygwin: fhandler_socket: Move shutdown and close methods into derived classes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
@@ -720,72 +720,6 @@ fhandler_socket::link (const char *newpath)
|
||||
return fhandler_base::link (newpath);
|
||||
}
|
||||
|
||||
int
|
||||
fhandler_socket::shutdown (int how)
|
||||
{
|
||||
int res = ::shutdown (get_socket (), how);
|
||||
|
||||
/* Linux allows to call shutdown for any socket, even if it's not connected.
|
||||
This also disables to call accept on this socket, if shutdown has been
|
||||
called with the SHUT_RD or SHUT_RDWR parameter. In contrast, WinSock
|
||||
only allows to call shutdown on a connected socket. The accept function
|
||||
is in no way affected. So, what we do here is to fake success, and to
|
||||
change the event settings so that an FD_CLOSE event is triggered for the
|
||||
calling Cygwin function. The evaluate_events method handles the call
|
||||
from accept specially to generate a Linux-compatible behaviour. */
|
||||
if (res && WSAGetLastError () != WSAENOTCONN)
|
||||
set_winsock_errno ();
|
||||
else
|
||||
{
|
||||
res = 0;
|
||||
switch (how)
|
||||
{
|
||||
case SHUT_RD:
|
||||
saw_shutdown_read (true);
|
||||
wsock_events->events |= FD_CLOSE;
|
||||
SetEvent (wsock_evt);
|
||||
break;
|
||||
case SHUT_WR:
|
||||
saw_shutdown_write (true);
|
||||
break;
|
||||
case SHUT_RDWR:
|
||||
saw_shutdown_read (true);
|
||||
saw_shutdown_write (true);
|
||||
wsock_events->events |= FD_CLOSE;
|
||||
SetEvent (wsock_evt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
fhandler_socket::close ()
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
release_events ();
|
||||
while ((res = ::closesocket (get_socket ())) != 0)
|
||||
{
|
||||
if (WSAGetLastError () != WSAEWOULDBLOCK)
|
||||
{
|
||||
set_winsock_errno ();
|
||||
res = -1;
|
||||
break;
|
||||
}
|
||||
if (cygwait (10) == WAIT_SIGNALED)
|
||||
{
|
||||
set_errno (EINTR);
|
||||
res = -1;
|
||||
break;
|
||||
}
|
||||
WSASetLastError (0);
|
||||
}
|
||||
|
||||
debug_printf ("%d = fhandler_socket::close()", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Definitions of old ifreq stuff used prior to Cygwin 1.7.0. */
|
||||
#define OLD_SIOCGIFFLAGS _IOW('s', 101, struct __old_ifreq)
|
||||
#define OLD_SIOCGIFADDR _IOW('s', 102, struct __old_ifreq)
|
||||
|
Reference in New Issue
Block a user