1
+ import os
2
+ import sys
1
3
import threading
2
4
import time
3
5
import socket
@@ -341,6 +343,12 @@ def __init__(self, session, xlog):
341
343
self .sock_conn_map = {}
342
344
self ._lock = threading .RLock ()
343
345
346
+ if sys .platform == "win32" :
347
+ self .slow_wait = 0.05
348
+ else :
349
+ self .slow_wait = 3
350
+ # self.slow_wait = 0.05
351
+
344
352
def status (self ):
345
353
out_string = "ConnectionPipe:\r \n "
346
354
out_string += " running: %s\r \n " % self .running
@@ -373,14 +381,18 @@ def add_sock_event(self, sock, conn, event):
373
381
374
382
with self ._lock :
375
383
self ._debug_log ("add_sock_event conn:%d event:%s" , conn .conn_id , event )
376
- self .sock_conn_map [sock ] = conn
377
384
try :
378
385
self .select2 .register_event (sock , event , conn )
379
386
except Exception as e :
380
387
self .xlog .warn ("add_sock_event %s conn:%d e:%r" , sock , conn .conn_id , e )
381
388
self .close_sock (sock , str (e ) + "_when_add_sock_event" )
382
389
return
383
390
391
+ # if sys.platform == "win32" and (sock not in self.sock_conn_map or event == selectors.EVENT_WRITE):
392
+ # self.notice_select()
393
+
394
+ self .sock_conn_map [sock ] = conn
395
+
384
396
if not self .th :
385
397
self .th = threading .Thread (target = self .pipe_worker , name = "x_tunnel_pipe_worker" )
386
398
self .th .start ()
@@ -438,6 +450,12 @@ def reset_all_connections(self):
438
450
self .sock_conn_map = {}
439
451
self .select2 = selectors .DefaultSelector ()
440
452
453
+ def notice_select (self ):
454
+ self .xlog .debug ("notice select" )
455
+
456
+ def read_notify (self ):
457
+ self .xlog .debug ("read_notify" )
458
+
441
459
def pipe_worker (self ):
442
460
timeout = 0.001
443
461
while self .running :
@@ -453,15 +471,15 @@ def pipe_worker(self):
453
471
if has_data :
454
472
timeout = 0.01
455
473
else :
456
- timeout = 3.0
474
+ timeout = self . slow_wait
457
475
458
476
# self.xlog.debug("%s recv select timeout switch to %f", random_id, timeout)
459
477
continue
460
478
else :
461
479
# self.xlog.debug("%s recv select timeout switch to 0.001", random_id)
462
480
timeout = 0.001
463
481
except Exception as e :
464
- self .xlog .warn ("Conn session:%s select except:%r" , self .session .session_id , e )
482
+ self .xlog .exception ("Conn session:%s select except:%r" , self .session .session_id , e )
465
483
if "Invalid argument" in str (e ):
466
484
self .reset_all_connections ()
467
485
time .sleep (1 )
@@ -471,6 +489,11 @@ def pipe_worker(self):
471
489
for key , event in events :
472
490
sock = key .fileobj
473
491
conn = key .data
492
+ if not conn :
493
+ self .xlog .debug ("get notice" )
494
+ self .read_notify ()
495
+ continue
496
+
474
497
if event & selectors .EVENT_READ :
475
498
try :
476
499
data = sock .recv (65535 )
0 commit comments