Skip to content

Commit

Permalink
optimized SocketSender
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryjiang committed Jan 11, 2025
1 parent a408d9c commit a40d41b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/SuperSocket.Connection/Sockets/SocketSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class SocketSender : SocketAsyncEventArgs, IValueTaskSource<int>, IResett

private static readonly Action<object?> _continuationCompleted = _ => { };

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / push

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / push

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / push

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / push

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / push

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / push

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / push

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / push

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / push

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 17 in src/SuperSocket.Connection/Sockets/SocketSender.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

private List<ArraySegment<byte>> _bufferList;

public SocketSender()
: base(unsafeSuppressExecutionContextFlow: true)
{
Expand Down Expand Up @@ -44,7 +46,12 @@ private void SetBuffer(in ReadOnlySequence<byte> buffer)
}
else
{
var bufferList = new List<ArraySegment<byte>>();
var bufferList = _bufferList;

if (bufferList == null)
{
_bufferList = bufferList = new List<ArraySegment<byte>>();
}

foreach (var piece in buffer)
{
Expand All @@ -70,6 +77,7 @@ protected override void OnCompleted(SocketAsyncEventArgs e)

public int GetResult(short token)
{
_continuation = null;
return BytesTransferred;
}

Expand Down Expand Up @@ -99,11 +107,10 @@ public void OnCompleted(Action<object> continuation, object state, short token,

public bool TryReset()
{
_continuation = null;

if (BufferList != null)
{
BufferList = null;
_bufferList?.Clear();
}
else
{
Expand Down

0 comments on commit a40d41b

Please sign in to comment.