Commit f6b6c94a authored by Akihiro Sagawa's avatar Akihiro Sagawa Committed by Alexandre Julliard

ws2_32: Fix ioctlsocket(FIONREAD) with listening socket.

parent 13b66d3d
...@@ -4648,12 +4648,24 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID ...@@ -4648,12 +4648,24 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
case WS_FIONREAD: case WS_FIONREAD:
{ {
#if defined(linux)
int listening = 0;
socklen_t len = sizeof(listening);
#endif
if (out_size != sizeof(WS_u_long) || IS_INTRESOURCE(out_buff)) if (out_size != sizeof(WS_u_long) || IS_INTRESOURCE(out_buff))
{ {
SetLastError(WSAEFAULT); SetLastError(WSAEFAULT);
return SOCKET_ERROR; return SOCKET_ERROR;
} }
if ((fd = get_sock_fd( s, 0, NULL )) == -1) return SOCKET_ERROR; if ((fd = get_sock_fd( s, 0, NULL )) == -1) return SOCKET_ERROR;
#if defined(linux)
/* On Linux, FIONREAD on listening socket always fails (see tcp(7)).
However, it succeeds on native. */
if (!getsockopt( fd, SOL_SOCKET, SO_ACCEPTCONN, &listening, &len ) && listening)
(*(WS_u_long *) out_buff) = 0;
else
#endif
if (ioctl(fd, FIONREAD, out_buff ) == -1) if (ioctl(fd, FIONREAD, out_buff ) == -1)
status = wsaErrno(); status = wsaErrno();
release_sock_fd( s, fd ); release_sock_fd( s, fd );
......
...@@ -5233,8 +5233,8 @@ static void test_ioctlsocket(void) ...@@ -5233,8 +5233,8 @@ static void test_ioctlsocket(void)
/* test FIONREAD with listening socket */ /* test FIONREAD with listening socket */
arg = 0xdeadbeef; arg = 0xdeadbeef;
ret = ioctlsocket(sock, FIONREAD, &arg); ret = ioctlsocket(sock, FIONREAD, &arg);
todo_wine ok(ret == 0, "ioctlsocket failed unexpectedly with error %d\n", WSAGetLastError()); ok(ret == 0, "ioctlsocket failed unexpectedly with error %d\n", WSAGetLastError());
todo_wine ok(arg == 0, "expected 0, got %u\n", arg); ok(arg == 0, "expected 0, got %u\n", arg);
closesocket(sock); closesocket(sock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment