[0.4.13][MSAFD] Fix non-blocking sockets support for recv() (#5575)

by porting back:
0.4.15-dev-6491-g 442f5dfab5 [MSAFD] Fix non-blocking sockets support for recv() (#5575) CORE-14486 for Nginx web server; Firefox 52, Mypal 29.3.0, New Moon 28 web browser
partially 0.4.15-dev-4492-g 03422451b3 [REACTOS] Add '\n' to debug logs. Only the [MSAFD] parts

Also strip some EOL-whitespace and sacrifice some good-path-TRACEs to not increase the binary sizes:

msafd.dll GCC8.4.0dbg RosBE2.2.2 master             155.648
msafd.dll GCC4.7.2dbg RosBE2.1.6 0.4.14  144.384 -> 142.336
msafd.dll GCC4.7.2dbg RosBE2.1.6 0.4.13  144.384 -> 142.336
msafd.dll GCC4.7.2dbg RosBE2.1.6 0.4.12  145.920 -> 144.896
msafd.dll GCC4.7.2dbg RosBE2.1.6 0.4.11  143.872 -> 141.824
msafd.dll GCC4.7.2dbg RosBE2.1.6 0.4.10  142.336 -> 140.800
msafd.dll GCC4.7.2dbg RosBE2.1.6 0.4. 9  142.336 -> 140.800
msafd.dll GCC4.7.2dbg RosBE2.1.6 0.4. 8  142.336 -> 140.800
msafd.dll GCC4.7.2dbg RosBE2.1.6 0.4. 7  142.336 -> 140.800
This commit is contained in:
Joachim Henze 2023-08-18 21:41:10 +02:00
parent a8e089428f
commit e39a612688
3 changed files with 28 additions and 37 deletions

View file

@ -70,9 +70,6 @@ WSPSocket(int AddressFamily,
INT Status; INT Status;
PSOCK_SHARED_INFO SharedData = NULL; PSOCK_SHARED_INFO SharedData = NULL;
TRACE("Creating Socket, getting TDI Name - AddressFamily (%d) SocketType (%d) Protocol (%d).\n",
AddressFamily, SocketType, Protocol);
if (lpProtocolInfo && lpProtocolInfo->dwServiceFlags3 != 0 && lpProtocolInfo->dwServiceFlags4 != 0) if (lpProtocolInfo && lpProtocolInfo->dwServiceFlags3 != 0 && lpProtocolInfo->dwServiceFlags4 != 0)
{ {
/* Duplpicating socket from different process */ /* Duplpicating socket from different process */
@ -220,7 +217,6 @@ WSPSocket(int AddressFamily,
if( Socket->SharedData->SocketType == SOCK_DGRAM || if( Socket->SharedData->SocketType == SOCK_DGRAM ||
Socket->SharedData->SocketType == SOCK_RAW ) Socket->SharedData->SocketType == SOCK_RAW )
{ {
TRACE("Connectionless socket\n");
Socket->SharedData->ServiceFlags1 |= XP1_CONNECTIONLESS; Socket->SharedData->ServiceFlags1 |= XP1_CONNECTIONLESS;
} }
Socket->Handle = INVALID_SOCKET; Socket->Handle = INVALID_SOCKET;
@ -413,8 +409,6 @@ ok:
Upcalls.lpWPUModifyIFSHandle(Socket->ProtocolInfo.dwCatalogEntryId, (SOCKET)Sock, lpErrno); Upcalls.lpWPUModifyIFSHandle(Socket->ProtocolInfo.dwCatalogEntryId, (SOCKET)Sock, lpErrno);
/* Return Socket Handle */ /* Return Socket Handle */
TRACE("Success %x\n", Sock);
return (SOCKET)Sock; return (SOCKET)Sock;
error: error:
@ -649,7 +643,7 @@ WSPCloseSocket(IN SOCKET Handle,
if(!NT_SUCCESS(Status)) if(!NT_SUCCESS(Status))
{ {
ERR("NtCreateEvent failed: 0x%08x", Status); ERR("NtCreateEvent failed: 0x%08x\n", Status);
return SOCKET_ERROR; return SOCKET_ERROR;
} }
@ -664,7 +658,7 @@ WSPCloseSocket(IN SOCKET Handle,
if (Status) if (Status)
{ {
if (lpErrno) *lpErrno = Status; if (lpErrno) *lpErrno = Status;
ERR("WSHNotify failed. Error 0x%#x", Status); ERR("WSHNotify failed. Error 0x%#x\n", Status);
NtClose(SockEvent); NtClose(SockEvent);
return SOCKET_ERROR; return SOCKET_ERROR;
} }
@ -1119,8 +1113,6 @@ WSPSelect(IN int nfds,
PollBufferSize = sizeof(*PollInfo) + ((HandleCount - 1) * sizeof(AFD_HANDLE)); PollBufferSize = sizeof(*PollInfo) + ((HandleCount - 1) * sizeof(AFD_HANDLE));
TRACE("HandleCount: %u BufferSize: %u\n", HandleCount, PollBufferSize);
/* Convert Timeout to NT Format */ /* Convert Timeout to NT Format */
if (timeout == NULL) if (timeout == NULL)
{ {
@ -1299,8 +1291,6 @@ WSPSelect(IN int nfds,
PollInfo, PollInfo,
PollBufferSize); PollBufferSize);
TRACE("DeviceIoControlFile => %x\n", Status);
/* Wait for Completion */ /* Wait for Completion */
if (Status == STATUS_PENDING) if (Status == STATUS_PENDING)
{ {
@ -1401,15 +1391,12 @@ WSPSelect(IN int nfds,
*lpErrno = WSAEINVAL; *lpErrno = WSAEINVAL;
break; break;
} }
TRACE("*lpErrno = %x\n", *lpErrno);
} }
HandleCount = (readfds ? readfds->fd_count : 0) + HandleCount = (readfds ? readfds->fd_count : 0) +
(writefds && writefds != readfds ? writefds->fd_count : 0) + (writefds && writefds != readfds ? writefds->fd_count : 0) +
(exceptfds && exceptfds != readfds && exceptfds != writefds ? exceptfds->fd_count : 0); (exceptfds && exceptfds != readfds && exceptfds != writefds ? exceptfds->fd_count : 0);
TRACE("%d events\n", HandleCount);
return HandleCount; return HandleCount;
} }
@ -1495,22 +1482,25 @@ WSPAccept(
ListenReceiveData = (PAFD_RECEIVED_ACCEPT_DATA)ReceiveBuffer; ListenReceiveData = (PAFD_RECEIVED_ACCEPT_DATA)ReceiveBuffer;
/* If this is non-blocking, make sure there's something for us to accept */ /* If this is non-blocking, make sure there's something for us to accept */
FD_ZERO(&ReadSet); if (Socket->SharedData->NonBlocking)
FD_SET(Socket->Handle, &ReadSet);
Timeout.tv_sec=0;
Timeout.tv_usec=0;
if (WSPSelect(0, &ReadSet, NULL, NULL, &Timeout, lpErrno) == SOCKET_ERROR)
{ {
NtClose(SockEvent); FD_ZERO(&ReadSet);
return SOCKET_ERROR; FD_SET(Socket->Handle, &ReadSet);
} Timeout.tv_sec=0;
Timeout.tv_usec=0;
if (ReadSet.fd_array[0] != Socket->Handle) if (WSPSelect(0, &ReadSet, NULL, NULL, &Timeout, lpErrno) == SOCKET_ERROR)
{ {
NtClose(SockEvent); NtClose(SockEvent);
if (lpErrno) *lpErrno = WSAEWOULDBLOCK; return SOCKET_ERROR;
return SOCKET_ERROR; }
if (ReadSet.fd_array[0] != Socket->Handle)
{
NtClose(SockEvent);
if (lpErrno) *lpErrno = WSAEWOULDBLOCK;
return SOCKET_ERROR;
}
} }
/* Send IOCTL */ /* Send IOCTL */
@ -1782,6 +1772,7 @@ WSPAccept(
AcceptSocketInfo->SharedData->State = SocketConnected; AcceptSocketInfo->SharedData->State = SocketConnected;
AcceptSocketInfo->SharedData->ConnectTime = GetCurrentTimeInSeconds(); AcceptSocketInfo->SharedData->ConnectTime = GetCurrentTimeInSeconds();
AcceptSocketInfo->SharedData->NonBlocking = Socket->SharedData->NonBlocking;
/* Return Address in SOCKADDR FORMAT */ /* Return Address in SOCKADDR FORMAT */
if( SocketAddress ) if( SocketAddress )
@ -1798,8 +1789,6 @@ WSPAccept(
/* Re-enable Async Event */ /* Re-enable Async Event */
SockReenableAsyncSelectEvent(Socket, FD_ACCEPT); SockReenableAsyncSelectEvent(Socket, FD_ACCEPT);
TRACE("Socket %x\n", AcceptSocket);
if (Status == STATUS_SUCCESS && (Socket->HelperEvents & WSH_NOTIFY_ACCEPT)) if (Status == STATUS_SUCCESS && (Socket->HelperEvents & WSH_NOTIFY_ACCEPT))
{ {
Status = Socket->HelperData->WSHNotify(Socket->HelperContext, Status = Socket->HelperData->WSHNotify(Socket->HelperContext,
@ -3014,7 +3003,6 @@ WSPStartup(
CatalogEntryId = lpProtocolInfo->dwCatalogEntryId; CatalogEntryId = lpProtocolInfo->dwCatalogEntryId;
} }
TRACE("Status (%d).\n", Status);
return Status; return Status;
} }
@ -3151,7 +3139,7 @@ WSPStringToAddress(IN LPWSTR AddressString,
/* move over the dot to next ip part */ /* move over the dot to next ip part */
(*bp)++; (*bp)++;
} }
/* check dots count */ /* check dots count */
if (numdots != 3) if (numdots != 3)
{ {
@ -3208,8 +3196,6 @@ WSPAPI
WSPCleanup(OUT LPINT lpErrno) WSPCleanup(OUT LPINT lpErrno)
{ {
TRACE("Leaving.\n");
if (lpErrno) *lpErrno = NO_ERROR; if (lpErrno) *lpErrno = NO_ERROR;
return 0; return 0;
@ -3412,7 +3398,6 @@ SetSocketInformation(PSOCKET_INFORMATION Socket,
/* Overlapped request for non overlapped opened socket */ /* Overlapped request for non overlapped opened socket */
if ((Socket->SharedData->CreateFlags & SO_SYNCHRONOUS_NONALERT) != 0) if ((Socket->SharedData->CreateFlags & SO_SYNCHRONOUS_NONALERT) != 0)
{ {
TRACE("Opened without flag WSA_FLAG_OVERLAPPED. Do nothing.\n");
NtClose( SockEvent ); NtClose( SockEvent );
return 0; return 0;
} }

View file

@ -189,7 +189,7 @@ WSPEnumNetworkEvents(
if (Status != STATUS_SUCCESS) if (Status != STATUS_SUCCESS)
{ {
ERR("Status 0x%08x", Status); ERR("Status 0x%08x\n", Status);
return MsafdReturnWithErrno(Status, lpErrno, 0, NULL); return MsafdReturnWithErrno(Status, lpErrno, 0, NULL);
} }

View file

@ -291,6 +291,12 @@ WSPRecv(SOCKET Handle,
NULL, NULL,
0); 0);
if (Status == STATUS_PENDING && Socket->SharedData->NonBlocking)
{
if (lpErrno) *lpErrno = WSAEWOULDBLOCK;
return SOCKET_ERROR;
}
/* Wait for completion of not overlapped */ /* Wait for completion of not overlapped */
if (Status == STATUS_PENDING && lpOverlapped == NULL) if (Status == STATUS_PENDING && lpOverlapped == NULL)
{ {