Skip to content

Commit

Permalink
Reuse ThrowForNonFreeStatus in StartOperationCommon
Browse files Browse the repository at this point in the history
It's not 100% the same logic as before; previously, if an operation was in progress while Dispose was called, and then another operation was issued while that previous operation was still in progress, this would throw an OperationDisposedException, whereas now it'll throw an InvalidOperationException until the previous operation completes, then it'll throw an OperationDisposedException.  But a) there are race conditions here, so code doing this needs to be able to handle both exceptions for the same failure, and b) the previous logic was inconsistent with the exact same kind of thing in StartConfiguring, for no good reason. This brings them in sink, and shares the same code, also reducing the size of StartOperationCommon.
  • Loading branch information
stephentoub committed Jun 14, 2017
1 parent 5f93963 commit ccc7034
Showing 1 changed file with 3 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,17 +443,10 @@ private void ThrowForNonFreeStatus(int status)
internal void StartOperationCommon(Socket socket)
{
// Change status to "in-use".
if (Interlocked.CompareExchange(ref _operating, InProgress, Free) != Free)
int status = Interlocked.CompareExchange(ref _operating, InProgress, Free);
if (status != Free)
{
// If it was already "in-use" check if Dispose was called.
if (_disposeCalled)
{
// Dispose was called - throw ObjectDisposed.
throw new ObjectDisposedException(GetType().FullName);
}

// Only one at a time.
throw new InvalidOperationException(SR.net_socketopinprogress);
ThrowForNonFreeStatus(status);
}

// Prepare execution context for callback.
Expand Down

0 comments on commit ccc7034

Please sign in to comment.