@@ -17,18 +17,18 @@ public partial class PooledSocket : IDisposable
1717 {
1818 private readonly ILogger _logger ;
1919
20- private bool isAlive ;
21- private Socket socket ;
22- private EndPoint endpoint ;
20+ private bool _isAlive ;
21+ private Socket _socket ;
22+ private EndPoint _endpoint ;
2323
24- private Stream inputStream ;
25- private AsyncSocketHelper helper ;
24+ private Stream _inputStream ;
25+ private AsyncSocketHelper _helper ;
2626
2727 public PooledSocket ( EndPoint endpoint , TimeSpan connectionTimeout , TimeSpan receiveTimeout , ILogger logger )
2828 {
2929 _logger = logger ;
3030
31- this . isAlive = true ;
31+ _isAlive = true ;
3232
3333 var socket = new Socket ( AddressFamily . InterNetwork , SocketType . Stream , ProtocolType . Tcp ) ;
3434 socket . NoDelay = true ;
@@ -49,10 +49,10 @@ public PooledSocket(EndPoint endpoint, TimeSpan connectionTimeout, TimeSpan rece
4949 throw new TimeoutException ( $ "Could not connect to { endpoint } .") ;
5050 }
5151
52- this . socket = socket ;
53- this . endpoint = endpoint ;
52+ _socket = socket ;
53+ _endpoint = endpoint ;
5454
55- this . inputStream = new NetworkStream ( socket ) ;
55+ _inputStream = new NetworkStream ( socket ) ;
5656 }
5757
5858 private bool ConnectWithTimeout ( Socket socket , EndPoint endpoint , int timeout )
@@ -89,24 +89,24 @@ void Cancel()
8989
9090 public int Available
9191 {
92- get { return this . socket . Available ; }
92+ get { return _socket . Available ; }
9393 }
9494
9595 public void Reset ( )
9696 {
9797 // discard any buffered data
98- this . inputStream . Flush ( ) ;
98+ _inputStream . Flush ( ) ;
9999
100- if ( this . helper != null ) this . helper . DiscardBuffer ( ) ;
100+ if ( _helper != null ) _helper . DiscardBuffer ( ) ;
101101
102- int available = this . socket . Available ;
102+ int available = _socket . Available ;
103103
104104 if ( available > 0 )
105105 {
106106 if ( _logger . IsEnabled ( LogLevel . Warning ) )
107107 _logger . LogWarning (
108108 "Socket bound to {0} has {1} unread data! This is probably a bug in the code. InstanceID was {2}." ,
109- this . socket . RemoteEndPoint , available , this . InstanceId ) ;
109+ _socket . RemoteEndPoint , available , this . InstanceId ) ;
110110
111111 byte [ ] data = new byte [ available ] ;
112112
@@ -127,7 +127,7 @@ public void Reset()
127127
128128 public bool IsAlive
129129 {
130- get { return this . isAlive ; }
130+ get { return _isAlive ; }
131131 }
132132
133133 /// <summary>
@@ -158,20 +158,20 @@ protected void Dispose(bool disposing)
158158
159159 try
160160 {
161- if ( socket != null )
161+ if ( _socket != null )
162162 try
163163 {
164- this . socket . Dispose ( ) ;
164+ _socket . Dispose ( ) ;
165165 }
166166 catch
167167 {
168168 }
169169
170- if ( this . inputStream != null )
171- this . inputStream . Dispose ( ) ;
170+ if ( _inputStream != null )
171+ _inputStream . Dispose ( ) ;
172172
173- this . inputStream = null ;
174- this . socket = null ;
173+ _inputStream = null ;
174+ _socket = null ;
175175 this . CleanupCallback = null ;
176176 }
177177 catch ( Exception e )
@@ -195,7 +195,7 @@ void IDisposable.Dispose()
195195
196196 private void CheckDisposed ( )
197197 {
198- if ( this . socket == null )
198+ if ( _socket == null )
199199 throw new ObjectDisposedException ( "PooledSocket" ) ;
200200 }
201201
@@ -209,11 +209,11 @@ public int ReadByte()
209209
210210 try
211211 {
212- return this . inputStream . ReadByte ( ) ;
212+ return _inputStream . ReadByte ( ) ;
213213 }
214214 catch ( IOException )
215215 {
216- this . isAlive = false ;
216+ _isAlive = false ;
217217
218218 throw ;
219219 }
@@ -225,11 +225,11 @@ public int ReadByteAsync()
225225
226226 try
227227 {
228- return this . inputStream . ReadByte ( ) ;
228+ return _inputStream . ReadByte ( ) ;
229229 }
230230 catch ( IOException )
231231 {
232- this . isAlive = false ;
232+ _isAlive = false ;
233233 throw ;
234234 }
235235 }
@@ -245,7 +245,7 @@ public async Task ReadAsync(byte[] buffer, int offset, int count)
245245 {
246246 try
247247 {
248- int currentRead = this . inputStream . Read ( buffer , offset , shouldRead ) ;
248+ int currentRead = _inputStream . Read ( buffer , offset , shouldRead ) ;
249249 if ( currentRead < 1 )
250250 continue ;
251251
@@ -255,7 +255,7 @@ public async Task ReadAsync(byte[] buffer, int offset, int count)
255255 }
256256 catch ( IOException )
257257 {
258- this . isAlive = false ;
258+ _isAlive = false ;
259259 throw ;
260260 }
261261 }
@@ -279,7 +279,7 @@ public void Read(byte[] buffer, int offset, int count)
279279 {
280280 try
281281 {
282- int currentRead = this . inputStream . Read ( buffer , offset , shouldRead ) ;
282+ int currentRead = _inputStream . Read ( buffer , offset , shouldRead ) ;
283283 if ( currentRead < 1 )
284284 continue ;
285285
@@ -289,7 +289,7 @@ public void Read(byte[] buffer, int offset, int count)
289289 }
290290 catch ( IOException )
291291 {
292- this . isAlive = false ;
292+ _isAlive = false ;
293293 throw ;
294294 }
295295 }
@@ -301,13 +301,13 @@ public void Write(byte[] data, int offset, int length)
301301
302302 SocketError status ;
303303
304- this . socket . Send ( data , offset , length , SocketFlags . None , out status ) ;
304+ _socket . Send ( data , offset , length , SocketFlags . None , out status ) ;
305305
306306 if ( status != SocketError . Success )
307307 {
308- this . isAlive = false ;
308+ _isAlive = false ;
309309
310- ThrowHelper . ThrowSocketWriteError ( this . endpoint , status ) ;
310+ ThrowHelper . ThrowSocketWriteError ( _endpoint , status ) ;
311311 }
312312 }
313313
@@ -322,29 +322,29 @@ public void Write(IList<ArraySegment<byte>> buffers)
322322 for ( int i = 0 , C = buffers . Count ; i < C ; i ++ )
323323 total += buffers [ i ] . Count ;
324324
325- if ( this . socket . Send ( buffers , SocketFlags . None , out status ) != total )
325+ if ( _socket . Send ( buffers , SocketFlags . None , out status ) != total )
326326 System . Diagnostics . Debugger . Break ( ) ;
327327#else
328328 this . socket . Send ( buffers , SocketFlags . None , out status ) ;
329329#endif
330330
331331 if ( status != SocketError . Success )
332332 {
333- this . isAlive = false ;
333+ _isAlive = false ;
334334
335- ThrowHelper . ThrowSocketWriteError ( this . endpoint , status ) ;
335+ ThrowHelper . ThrowSocketWriteError ( _endpoint , status ) ;
336336 }
337337 }
338338
339339 public async Task WriteSync ( IList < ArraySegment < byte > > buffers )
340340 {
341341 try
342342 {
343- await socket . SendAsync ( buffers , SocketFlags . None ) ;
343+ await _socket . SendAsync ( buffers , SocketFlags . None ) ;
344344 }
345345 catch ( Exception ex )
346346 {
347- isAlive = false ;
347+ _isAlive = false ;
348348 _logger . LogError ( ex , nameof ( PooledSocket . WriteSync ) ) ;
349349 }
350350 }
@@ -365,10 +365,10 @@ public bool ReceiveAsync(AsyncIOArgs p)
365365 return false ;
366366 }
367367
368- if ( this . helper == null )
369- this . helper = new AsyncSocketHelper ( this ) ;
368+ if ( _helper == null )
369+ _helper = new AsyncSocketHelper ( this ) ;
370370
371- return this . helper . Read ( p ) ;
371+ return _helper . Read ( p ) ;
372372 }
373373 }
374374}
0 commit comments