@@ -127,6 +127,7 @@ public interface NetHandler
127
127
public class NetManager
128
128
{
129
129
private bool inited = false ;
130
+ private bool running = true ;
130
131
private readonly List < NetHandlerImpl > sockets = new List < NetHandlerImpl > ( ) ;
131
132
private readonly List < NetHandlerImpl > newsockets = new List < NetHandlerImpl > ( ) ;
132
133
private readonly List < NetHandlerImpl > deletesockets = new List < NetHandlerImpl > ( ) ;
@@ -186,7 +187,7 @@ private void Init()
186
187
187
188
byte [ ] bytes = new byte [ 64 * 1024 ] ;
188
189
189
- while ( true )
190
+ while ( running )
190
191
{
191
192
if ( newsockets . Count > 0 )
192
193
{
@@ -231,7 +232,7 @@ private void Init()
231
232
if ( socket . need_send )
232
233
writers . Add ( socket ) ;
233
234
}
234
- Socket . Select ( reads , writers , errors , - 1 ) ;
235
+ Socket . Select ( reads , writers , errors , 5 ) ;
235
236
for ( int i = 0 ; i < writers . Count ; i ++ )
236
237
{
237
238
NetHandlerImpl socket = writers [ i ] ;
@@ -340,7 +341,7 @@ public void Listen(int port, Accepted callback)
340
341
}
341
342
}
342
343
ctrl . Callback = callback ;
343
- while ( true )
344
+ while ( running )
344
345
{
345
346
if ( ! server . Server . Poll ( 1000 , SelectMode . SelectRead ) )
346
347
{
@@ -385,6 +386,11 @@ public void Stop(int port)
385
386
}
386
387
}
387
388
389
+ public void Exit ( )
390
+ {
391
+ running = false ;
392
+ }
393
+
388
394
public delegate void Connected ( NetHandler handler , bool success ) ;
389
395
390
396
public NetHandler Connect ( string ipport , int timeout )
@@ -610,7 +616,7 @@ public void Write(IntPtr bytes, int length)
610
616
}
611
617
}
612
618
613
- public NetListener Listen
619
+ public new NetListener Listen
614
620
{
615
621
get { return listen ; }
616
622
set { listen = value ; }
0 commit comments