@@ -359,22 +359,22 @@ _dispatch_socket_callback(PTP_CALLBACK_INSTANCE inst, void *context,
359
359
DWORD dwBytesAvailable = 1 ;
360
360
if (lNetworkEvents & FD_CLOSE ) {
361
361
dwBytesAvailable = 0 ;
362
- // Post to all registered read and write handlers
363
- lNetworkEvents |= FD_READ | FD_WRITE ;
364
362
} else if (lNetworkEvents & FD_READ ) {
365
363
ioctlsocket (sock , FIONREAD , & dwBytesAvailable );
366
364
}
367
- if (lNetworkEvents & FD_READ ) {
365
+ if ((lNetworkEvents & FD_CLOSE ) ||
366
+ ((lNetworkEvents & FD_READ ) && (dwBytesAvailable > 0 ))) {
368
367
_dispatch_muxnote_retain (dmn );
369
368
if (!PostQueuedCompletionStatus (hPort , dwBytesAvailable ,
370
369
(ULONG_PTR )DISPATCH_PORT_SOCKET_READ , (LPOVERLAPPED )dmn )) {
371
370
DISPATCH_INTERNAL_CRASH (GetLastError (),
372
371
"PostQueuedCompletionStatus" );
373
372
}
374
373
}
375
- if (lNetworkEvents & FD_WRITE ) {
374
+ if (( lNetworkEvents & FD_CLOSE ) || ( lNetworkEvents & FD_WRITE ) ) {
376
375
_dispatch_muxnote_retain (dmn );
377
- if (!PostQueuedCompletionStatus (hPort , dwBytesAvailable ,
376
+ if (!PostQueuedCompletionStatus (hPort ,
377
+ lNetworkEvents & FD_CLOSE ? 0 : 1 ,
378
378
(ULONG_PTR )DISPATCH_PORT_SOCKET_WRITE , (LPOVERLAPPED )dmn )) {
379
379
DISPATCH_INTERNAL_CRASH (GetLastError (),
380
380
"PostQueuedCompletionStatus" );
0 commit comments