Cygwin: fhandler_socket: Add derived ioctl methods

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen
2018-02-22 16:30:08 +01:00
parent 233bde3125
commit 79598f94f7
4 changed files with 128 additions and 50 deletions

View File

@ -1907,3 +1907,60 @@ fhandler_socket_local::getsockopt (int level, int optname, const void *optval,
return ret;
}
int
fhandler_socket_local::ioctl (unsigned int cmd, void *p)
{
int res;
switch (cmd)
{
/* FIXME: These have to be handled differently in future. */
case FIOASYNC:
#ifdef __x86_64__
case _IOW('f', 125, u_long):
#endif
res = WSAAsyncSelect (get_socket (), winmsg, WM_ASYNCIO,
*(int *) p ? ASYNC_MASK : 0);
syscall_printf ("Async I/O on socket %s",
*(int *) p ? "started" : "cancelled");
async_io (*(int *) p != 0);
/* If async_io is switched off, revert the event handling. */
if (*(int *) p == 0)
WSAEventSelect (get_socket (), wsock_evt, EVENT_MASK);
break;
case FIONREAD:
#ifdef __x86_64__
case _IOR('f', 127, u_long):
#endif
/* Make sure to use the Winsock definition of FIONREAD. */
res = ::ioctlsocket (get_socket (), _IOR('f', 127, u_long), (u_long *) p);
if (res == SOCKET_ERROR)
set_winsock_errno ();
break;
case FIONBIO:
case SIOCATMARK:
/* Sockets are always non-blocking internally. So we just note the
state here. */
#ifdef __x86_64__
/* Convert the different idea of u_long in the definition of cmd. */
if (((cmd >> 16) & IOCPARM_MASK) == sizeof (unsigned long))
cmd = (cmd & ~(IOCPARM_MASK << 16)) | (sizeof (u_long) << 16);
#endif
if (cmd == FIONBIO)
{
syscall_printf ("socket is now %sblocking",
*(int *) p ? "non" : "");
set_nonblocking (*(int *) p);
res = 0;
}
else
res = ::ioctlsocket (get_socket (), cmd, (u_long *) p);
break;
default:
res = fhandler_socket::ioctl (cmd, p);
break;
}
syscall_printf ("%d = ioctl_socket(%x, %p)", res, cmd, p);
return res;
}