Commit 1184fe90 authored by Bruno Jesus's avatar Bruno Jesus Committed by Alexandre Julliard

ws2_32: Avoid memory allocation for simple receives.

parent 75221939
...@@ -6531,8 +6531,8 @@ static int WS2_recv_base( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, ...@@ -6531,8 +6531,8 @@ static int WS2_recv_base( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
LPWSABUF lpControlBuffer ) LPWSABUF lpControlBuffer )
{ {
unsigned int i, options; unsigned int i, options;
int n, fd, err; int n, fd, err, overlapped;
struct ws2_async *wsa; struct ws2_async *wsa, localwsa;
BOOL is_blocking; BOOL is_blocking;
DWORD timeout_start = GetTickCount(); DWORD timeout_start = GetTickCount();
ULONG_PTR cvalue = (lpOverlapped && ((ULONG_PTR)lpOverlapped->hEvent & 1) == 0) ? (ULONG_PTR)lpOverlapped : 0; ULONG_PTR cvalue = (lpOverlapped && ((ULONG_PTR)lpOverlapped->hEvent & 1) == 0) ? (ULONG_PTR)lpOverlapped : 0;
...@@ -6547,11 +6547,18 @@ static int WS2_recv_base( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, ...@@ -6547,11 +6547,18 @@ static int WS2_recv_base( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
if (fd == -1) return SOCKET_ERROR; if (fd == -1) return SOCKET_ERROR;
overlapped = (lpOverlapped || lpCompletionRoutine) &&
!(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT));
if (overlapped || dwBufferCount > 1)
{
if (!(wsa = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET(struct ws2_async, iovec[dwBufferCount]) ))) if (!(wsa = HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET(struct ws2_async, iovec[dwBufferCount]) )))
{ {
err = WSAEFAULT; err = WSAEFAULT;
goto error; goto error;
} }
}
else
wsa = &localwsa;
wsa->hSocket = SOCKET2HANDLE(s); wsa->hSocket = SOCKET2HANDLE(s);
wsa->flags = *lpFlags; wsa->flags = *lpFlags;
...@@ -6588,8 +6595,7 @@ static int WS2_recv_base( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, ...@@ -6588,8 +6595,7 @@ static int WS2_recv_base( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
} }
else if (lpNumberOfBytesRecvd) *lpNumberOfBytesRecvd = n; else if (lpNumberOfBytesRecvd) *lpNumberOfBytesRecvd = n;
if ((lpOverlapped || lpCompletionRoutine) && if (overlapped)
!(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT)))
{ {
IO_STATUS_BLOCK *iosb = lpOverlapped ? (IO_STATUS_BLOCK *)lpOverlapped : &wsa->local_iosb; IO_STATUS_BLOCK *iosb = lpOverlapped ? (IO_STATUS_BLOCK *)lpOverlapped : &wsa->local_iosb;
...@@ -6673,14 +6679,14 @@ static int WS2_recv_base( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, ...@@ -6673,14 +6679,14 @@ static int WS2_recv_base( SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
} }
TRACE(" -> %i bytes\n", n); TRACE(" -> %i bytes\n", n);
HeapFree( GetProcessHeap(), 0, wsa ); if (wsa != &localwsa) HeapFree( GetProcessHeap(), 0, wsa );
release_sock_fd( s, fd ); release_sock_fd( s, fd );
_enable_event(SOCKET2HANDLE(s), FD_READ, 0, 0); _enable_event(SOCKET2HANDLE(s), FD_READ, 0, 0);
return 0; return 0;
error: error:
HeapFree( GetProcessHeap(), 0, wsa ); if (wsa != &localwsa) HeapFree( GetProcessHeap(), 0, wsa );
release_sock_fd( s, fd ); release_sock_fd( s, fd );
WARN(" -> ERROR %d\n", err); WARN(" -> ERROR %d\n", err);
WSASetLastError( err ); WSASetLastError( err );
......
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