Skip to content

Commit

Permalink
Modified handling of Success property if socket is aborted before com…
Browse files Browse the repository at this point in the history
…pletion status is handled
  • Loading branch information
Michael Southworth authored and Michael Southworth committed Apr 18, 2017
1 parent 32265ae commit 57f42a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
20 changes: 13 additions & 7 deletions Source/AsyncIO/Windows/CompletionPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,22 @@ private void HandleCompletionStatus(out CompletionStatus completionStatus, IntPt
{
SocketError socketError = SocketError.Success;
SocketFlags socketFlags;

bool operationSucceed = UnsafeMethods.WSAGetOverlappedResult(overlapped.AsyncSocket.Handle,
overlappedAddress,
out bytesTransferred, false, out socketFlags);

if (!operationSucceed)
if(overlapped.Disposed)
{
socketError = (SocketError)Marshal.GetLastWin32Error();
socketError = SocketError.OperationAborted;
}
else
{
bool operationSucceed = UnsafeMethods.WSAGetOverlappedResult(overlapped.AsyncSocket.Handle,
overlappedAddress,
out bytesTransferred, false, out socketFlags);

if (!operationSucceed)
{
socketError = (SocketError)Marshal.GetLastWin32Error();
}

}
completionStatus = new CompletionStatus(overlapped.AsyncSocket, overlapped.State,
overlapped.OperationType, socketError,
bytesTransferred);
Expand Down
10 changes: 6 additions & 4 deletions Source/AsyncIO/Windows/Overlapped.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ public IntPtr Address

public Windows.Socket AsyncSocket { get; private set; }

public bool Success
{
get { return Marshal.ReadIntPtr(m_address).Equals(IntPtr.Zero); }
}
public bool Success { get; private set; }

public bool InProgress { get; private set; }

Expand All @@ -91,6 +88,11 @@ public static Overlapped CompleteOperation(IntPtr overlappedAddress)
if (overlapped.Disposed)
{
overlapped.Free();
overlapped.Success = false;
}
else
{
overlapped.Success = Marshal.ReadIntPtr(overlapped.m_address).Equals(IntPtr.Zero);
}

return overlapped;
Expand Down

0 comments on commit 57f42a4

Please sign in to comment.