@@ -104,7 +104,7 @@ protected virtual void HandleAsyncConnection(IAsyncResult res)
104104 client . ReceiveTimeout = TransmitTimeout ;
105105 byte [ ] buff = new byte [ client . ReceiveBufferSize ] ;
106106 client . GetStream ( ) . ReadTimeout = TransmitTimeout ;
107- BoxTCPClient carclient = new BoxTCPClient ( client ) ;
107+ BoxTCPClient carclient = new BoxTCPClient ( client ) { IsAlive = true } ;
108108 RecState state = new RecState { Client = carclient , Buffer = buff } ;
109109 this . OnComClientConnected ? . Invoke ( carclient ) ;
110110 state . Stream . BeginRead ( state . Buffer , 0 , state . Buffer . Length , HandleClientAsyncRec , state ) ;
@@ -118,16 +118,18 @@ protected virtual void HandleClientAsyncRec(IAsyncResult res)
118118 return ;
119119 RecState state = ( RecState ) res . AsyncState ;
120120 TcpClient client = state . Client . Client ;
121- byte [ ] oldbuff = state . Buffer ;
122- NetworkStream ns = state . Stream ;
123121 if ( client == null )
124122 return ;
125- if ( client . Connected == false )
123+
124+ byte [ ] oldbuff = state . Buffer ;
125+
126+ if ( client . Connected == false )
126127 {
127128 this . OnComClientDisconneted ? . Invoke ( state . Client ) ;
128129 state . Client . Disconnected ( ) ;
130+ return ;
129131 }
130-
132+ NetworkStream ns = state . Stream ;
131133
132134 int b2r = 0 ;
133135 try
@@ -139,6 +141,10 @@ protected virtual void HandleClientAsyncRec(IAsyncResult res)
139141 {
140142 b2r = 0 ;
141143 }
144+ catch ( SocketException )
145+ {
146+ b2r = 0 ;
147+ }
142148 catch ( ObjectDisposedException )
143149 {
144150 return ;
@@ -160,7 +166,8 @@ protected virtual void HandleClientAsyncRec(IAsyncResult res)
160166
161167 else
162168 {
163- if ( AsyncRecBuffer )
169+ state . Client . IsAlive = true ;
170+ if ( AsyncRecBuffer )
164171 {
165172 byte [ ] buffer = new byte [ b2r ] ;
166173 Buffer . BlockCopy ( state . Buffer , 0 , buffer , 0 , b2r ) ;
0 commit comments