Skip to content

Commit 0ee5ec5

Browse files
committed
[MSWSOCK]
- AFD_EVENT_CLOSE also triggers on FD_CLOSE - Fix a deadlock after calling WSPEnumNetworkEvents - Fix a deadlock when calling WSPSend on an unbound socket - Leave the critical section while waiting - Firefox (and many other applications) work now svn path=/branches/aicom-network-branch/; revision=48526
1 parent 7640fe7 commit 0ee5ec5

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

dll/win32/mswsock/msafd/accept.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ SockCoreAccept(IN PSOCKET_INFORMATION Socket,
2727
HANDLE EventObject = NULL;
2828
ULONG AsyncEvents = 0, NetworkEvents = 0;
2929
CHAR HelperBuffer[256];
30-
30+
3131
/* Set the new state */
3232
AcceptedSocket->SharedData.State = SocketConnected;
3333

@@ -82,8 +82,7 @@ SockCoreAccept(IN PSOCKET_INFORMATION Socket,
8282
HelperContextSize);
8383
if (!HelperContext)
8484
{
85-
/* Unlock the socket and fail */
86-
LeaveCriticalSection(&Socket->Lock);
85+
/* Fail */
8786
return WSAENOBUFS;
8887
}
8988
}
@@ -99,9 +98,6 @@ SockCoreAccept(IN PSOCKET_INFORMATION Socket,
9998
&HelperContextSize);
10099
}
101100

102-
/* We're done with the old socket, so we can release the lock */
103-
LeaveCriticalSection(&Socket->Lock);
104-
105101
/* Get the TDI Handles for the new socket */
106102
ErrorCode = SockGetTdiHandles(AcceptedSocket);
107103

@@ -311,6 +307,7 @@ WSPAccept(SOCKET Handle,
311307
NULL,
312308
&Timeout,
313309
lpErrno);
310+
314311
if (ReturnValue == SOCKET_ERROR)
315312
{
316313
/* Fail */
@@ -412,10 +409,13 @@ WSPAccept(SOCKET Handle,
412409
if (Status == STATUS_PENDING)
413410
{
414411
/* Wait for completion */
412+
LeaveCriticalSection(&Socket->Lock);
415413
SockWaitForSingleObject(ThreadData->EventHandle,
416414
Handle,
417415
NO_BLOCKING_HOOK,
418416
NO_TIMEOUT);
417+
EnterCriticalSection(&Socket->Lock);
418+
419419
/* Get new status */
420420
Status = IoStatusBlock.Status;
421421
}
@@ -462,10 +462,13 @@ WSPAccept(SOCKET Handle,
462462
if (Status == STATUS_PENDING)
463463
{
464464
/* Wait for completion */
465+
LeaveCriticalSection(&Socket->Lock);
465466
SockWaitForSingleObject(ThreadData->EventHandle,
466467
Handle,
467468
NO_BLOCKING_HOOK,
468469
NO_TIMEOUT);
470+
EnterCriticalSection(&Socket->Lock);
471+
469472
/* Get new status */
470473
Status = IoStatusBlock.Status;
471474
}

dll/win32/mswsock/msafd/eventsel.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ SockEventSelectHelper(IN PSOCKET_INFORMATION Socket,
7272

7373
/* Send close event. Note, this includes both aborts and disconnects */
7474
if (Events & FD_CLOSE) PollInfo.Events |= AFD_EVENT_DISCONNECT |
75+
AFD_EVENT_CLOSE |
7576
AFD_EVENT_ABORT;
7677

7778
/* Send PnP events related to live network hardware changes */
@@ -99,10 +100,12 @@ SockEventSelectHelper(IN PSOCKET_INFORMATION Socket,
99100
if (Status == STATUS_PENDING)
100101
{
101102
/* Wait for completion */
103+
LeaveCriticalSection(&Socket->Lock);
102104
SockWaitForSingleObject(ThreadData->EventHandle,
103105
Socket->Handle,
104106
NO_BLOCKING_HOOK,
105107
NO_TIMEOUT);
108+
EnterCriticalSection(&Socket->Lock);
106109

107110
/* Get new status */
108111
Status = IoStatusBlock.Status;
@@ -273,10 +276,12 @@ WSPEnumNetworkEvents(IN SOCKET Handle,
273276
if (Status == STATUS_PENDING)
274277
{
275278
/* Wait for completion */
279+
LeaveCriticalSection(&Socket->Lock);
276280
SockWaitForSingleObject(ThreadData->EventHandle,
277281
Socket->Handle,
278282
NO_BLOCKING_HOOK,
279283
NO_TIMEOUT);
284+
EnterCriticalSection(&Socket->Lock);
280285

281286
/* Get new status */
282287
Status = IoStatusBlock.Status;
@@ -411,7 +416,11 @@ WSPEnumNetworkEvents(IN SOCKET Handle,
411416

412417
error:
413418
/* Dereference the socket, if we have one here */
414-
if (Socket) SockDereferenceSocket(Socket);
419+
if (Socket)
420+
{
421+
LeaveCriticalSection(&Socket->Lock);
422+
SockDereferenceSocket(Socket);
423+
}
415424

416425
/* Check for error */
417426
if (ErrorCode != NO_ERROR)

dll/win32/mswsock/msafd/send.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ WSPSendTo(SOCKET Handle,
246246
INT SockaddrLength;
247247
PSOCKADDR Sockaddr;
248248
SOCKADDR_INFO SocketInfo;
249-
249+
250250
/* Enter prolog */
251251
ErrorCode = SockEnterApiFast(&ThreadData);
252252
if (ErrorCode != NO_ERROR)
@@ -377,6 +377,8 @@ WSPSendTo(SOCKET Handle,
377377
/* Make sure it's still unbound */
378378
if (Socket->SharedData.State == SocketOpen)
379379
{
380+
LeaveCriticalSection(&Socket->Lock);
381+
380382
/* Bind it */
381383
ReturnValue = WSPBind(Handle,
382384
Sockaddr,
@@ -387,12 +389,13 @@ WSPSendTo(SOCKET Handle,
387389
{
388390
/* It's bound now, fake success */
389391
ReturnValue = NO_ERROR;
392+
393+
LeaveCriticalSection(&Socket->Lock);
390394
}
391395

392-
/* Release the lock and free memory */
393-
LeaveCriticalSection(&Socket->Lock);
396+
/* Free memory */
394397
RtlFreeHeap(SockPrivateHeap, 0, Sockaddr);
395-
398+
396399
/* Check if we failed */
397400
if (ReturnValue == SOCKET_ERROR) goto error;
398401
}

0 commit comments

Comments
 (0)