Skip to content

Commit

Permalink
Remove a few unnecessary state machines from SocketsHttpHandler (dotn…
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Jul 22, 2021
1 parent 290430e commit bc7b910
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ static async ValueTask WriteChunkAsync(HttpConnection connection, ReadOnlyMemory
}
}

public override async ValueTask FinishAsync(bool async)
public override Task FinishAsync(bool async)
{
// Send 0 byte chunk to indicate end, then final CrLf
HttpConnection connection = GetConnectionOrThrow();
_connection = null;
await connection.WriteBytesAsync(s_finalChunkBytes, async).ConfigureAwait(false);
return connection.WriteBytesAsync(s_finalChunkBytes, async);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationTo
return connection.WriteAsync(buffer, async: true);
}

public override ValueTask FinishAsync(bool async)
public override Task FinishAsync(bool async)
{
_connection = null;
return default;
return Task.CompletedTask;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1788,20 +1788,24 @@ private async ValueTask<int> ReadBufferedAsyncCore(Memory<byte> destination)
return bytesToCopy;
}

private async ValueTask CopyFromBufferAsync(Stream destination, bool async, int count, CancellationToken cancellationToken)
private ValueTask CopyFromBufferAsync(Stream destination, bool async, int count, CancellationToken cancellationToken)
{
Debug.Assert(count <= _readLength - _readOffset);

if (NetEventSource.Log.IsEnabled()) Trace($"Copying {count} bytes to stream.");

int offset = _readOffset;
_readOffset += count;

if (async)
{
await destination.WriteAsync(new ReadOnlyMemory<byte>(_readBuffer, _readOffset, count), cancellationToken).ConfigureAwait(false);
return destination.WriteAsync(new ReadOnlyMemory<byte>(_readBuffer, offset, count), cancellationToken);
}
else
{
destination.Write(_readBuffer, _readOffset, count);
destination.Write(_readBuffer, offset, count);
return default;
}
_readOffset += count;
}

private Task CopyToUntilEofAsync(Stream destination, bool async, int bufferSize, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public sealed override Task FlushAsync(CancellationToken ignored)

public sealed override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) => throw new NotSupportedException();

public abstract ValueTask FinishAsync(bool async);
public abstract Task FinishAsync(bool async);
}
}
}

0 comments on commit bc7b910

Please sign in to comment.