@@ -27,7 +27,7 @@ sealed class DefaultTcpSocketClient(IOptions<TcpSocketClientOptions> options) :
2727 /// <summary>
2828 /// <inheritdoc/>
2929 /// </summary>
30- public IPEndPoint LocalEndPoint => _localEndPoint ?? _options . LocalEndPoint ;
30+ public IPEndPoint LocalEndPoint => _localEndPoint ?? Options . LocalEndPoint ;
3131
3232 /// <summary>
3333 /// <inheritdoc/>
@@ -97,7 +97,7 @@ public async ValueTask<bool> ConnectAsync(IPEndPoint endPoint, CancellationToken
9797 ret = true ;
9898 }
9999
100- if ( _options . IsAutoReceive )
100+ if ( Options . IsAutoReceive )
101101 {
102102 _ = Task . Run ( AutoReceiveAsync , CancellationToken . None ) . ConfigureAwait ( false ) ;
103103 }
@@ -117,7 +117,7 @@ private async ValueTask AutoReceiveAsync()
117117 // 自动接收方法
118118 _autoReceiveTokenSource ??= new ( ) ;
119119
120- using var block = MemoryPool < byte > . Shared . Rent ( _options . ReceiveBufferSize ) ;
120+ using var block = MemoryPool < byte > . Shared . Rent ( Options . ReceiveBufferSize ) ;
121121 var buffer = block . Memory ;
122122 while ( _autoReceiveTokenSource is { IsCancellationRequested : false } )
123123 {
@@ -133,10 +133,10 @@ private async ValueTask<int> ReceiveCoreAsync(Memory<byte> buffer, CancellationT
133133 if ( _client is { Connected : true } )
134134 {
135135 var receiveToken = token ;
136- if ( _options . ReceiveTimeout > 0 )
136+ if ( Options . ReceiveTimeout > 0 )
137137 {
138138 // 设置接收超时时间
139- using var receiveTokenSource = new CancellationTokenSource ( _options . ReceiveTimeout ) ;
139+ using var receiveTokenSource = new CancellationTokenSource ( Options . ReceiveTimeout ) ;
140140 using var link = CancellationTokenSource . CreateLinkedTokenSource ( receiveToken , receiveTokenSource . Token ) ;
141141 receiveToken = link . Token ;
142142 }
@@ -178,7 +178,14 @@ public async ValueTask<bool> SendAsync(ReadOnlyMemory<byte> data, CancellationTo
178178 var ret = false ;
179179 if ( _sender != null )
180180 {
181- ret = await _sender . SendAsync ( data , token ) ;
181+ var sendToken = token ;
182+ if ( Options . SendTimeout > 0 )
183+ {
184+ using var sendTokenSource = new CancellationTokenSource ( Options . SendTimeout ) ;
185+ using var link = CancellationTokenSource . CreateLinkedTokenSource ( token , sendTokenSource . Token ) ;
186+ sendToken = link . Token ;
187+ }
188+ ret = await _sender . SendAsync ( data , sendToken ) ;
182189 }
183190
184191 return ret ;
0 commit comments