Skip to content

Commit

Permalink
删除多余的对象池
Browse files Browse the repository at this point in the history
  • Loading branch information
chawolbaka committed May 21, 2023
1 parent 86656ee commit d70b6b9
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions Protocol.Core/IO/NetworkListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public abstract partial class NetworkListener : INetworkListener
public event CommonEventHandler<object, ListenEventArgs> StopListen;
public event CommonEventHandler<object, UnhandledIOExceptionEventArgs> UnhandledException;

protected static IPool<SocketAsyncEventArgs> SAEAPool = new SocketAsyncEventArgsPool();

internal static Bucket<byte> _bufferPool;
protected CancellationTokenSource _internalToken;
protected Socket _socket;
Expand Down Expand Up @@ -63,14 +61,11 @@ public virtual void Start(CancellationToken token = default)
token.Register(_internalToken.Cancel);

EventUtils.InvokeCancelEvent(StartListen, this, new ListenEventArgs(false));
SocketAsyncEventArgs eventArgs = _usePool ? SAEAPool.Rent() : new SocketAsyncEventArgs();
if (_usePool)
_internalToken.Token.Register(() => SAEAPool.Return(eventArgs));

SocketAsyncEventArgs eventArgs = new SocketAsyncEventArgs();

_internalToken.Token.Register(() => EventUtils.InvokeCancelEvent(StopListen, this, new ListenEventArgs(true)));
eventArgs.RemoteEndPoint = _socket.RemoteEndPoint;
eventArgs.SetBuffer(_buffer);
eventArgs.Completed -= OnReceiveCompleted;
eventArgs.Completed += OnReceiveCompleted;
ReceiveNextBuffer(eventArgs);
}
Expand All @@ -80,7 +75,7 @@ public virtual void Start(CancellationToken token = default)
private void OnReceiveCompleted(object sender, SocketAsyncEventArgs e)
{
//检查连接状态
if (e.SocketError != SocketError.Success)
if (e.SocketError != SocketError.Success)
{
InvokeUnhandledException(new SocketException((int)e.SocketError));
_internalToken.Cancel();
Expand Down

0 comments on commit d70b6b9

Please sign in to comment.