Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ public bool StartAsyncOperation(SocketAsyncContext context, TOperation operation
}
}

public AsyncOperation? ProcessSyncEventOrGetAsyncEvent(SocketAsyncContext context)
public AsyncOperation? ProcessSyncEventOrGetAsyncEvent(SocketAsyncContext context, bool skipAsyncEvents = false)
{
AsyncOperation op;
using (Lock())
Expand All @@ -860,8 +860,16 @@ public bool StartAsyncOperation(SocketAsyncContext context, TOperation operation

case QueueState.Waiting:
Debug.Assert(_tail != null, "State == Waiting but queue is empty!");
_state = QueueState.Processing;
op = _tail.Next;
Debug.Assert(_isNextOperationSynchronous == (op.Event != null));
if (skipAsyncEvents && !_isNextOperationSynchronous)
{
// Return the operation to indicate that the async operation was not processed, without making
// any state changes because async operations are being skipped
return op;
}

_state = QueueState.Processing;
// Break out and release lock
break;

Expand Down Expand Up @@ -892,6 +900,7 @@ public bool StartAsyncOperation(SocketAsyncContext context, TOperation operation
else
{
// Async operation. The caller will figure out how to process the IO.
Debug.Assert(!skipAsyncEvents);
return op;
}
}
Expand Down Expand Up @@ -1998,14 +2007,14 @@ public unsafe Interop.Sys.SocketEvents HandleSyncEventsSpeculatively(Interop.Sys

if ((events & Interop.Sys.SocketEvents.Read) != 0 &&
_receiveQueue.IsNextOperationSynchronous_Speculative &&
_receiveQueue.ProcessSyncEventOrGetAsyncEvent(this) == null)
_receiveQueue.ProcessSyncEventOrGetAsyncEvent(this, skipAsyncEvents: true) == null)
{
events ^= Interop.Sys.SocketEvents.Read;
}

if ((events & Interop.Sys.SocketEvents.Write) != 0 &&
_sendQueue.IsNextOperationSynchronous_Speculative &&
_sendQueue.ProcessSyncEventOrGetAsyncEvent(this) == null)
_sendQueue.ProcessSyncEventOrGetAsyncEvent(this, skipAsyncEvents: true) == null)
{
events ^= Interop.Sys.SocketEvents.Write;
}
Expand Down