1+ import os
2+ import sys
13import threading
24import time
35import socket
@@ -341,6 +343,12 @@ def __init__(self, session, xlog):
341343 self .sock_conn_map = {}
342344 self ._lock = threading .RLock ()
343345
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+
344352 def status (self ):
345353 out_string = "ConnectionPipe:\r \n "
346354 out_string += " running: %s\r \n " % self .running
@@ -373,14 +381,18 @@ def add_sock_event(self, sock, conn, event):
373381
374382 with self ._lock :
375383 self ._debug_log ("add_sock_event conn:%d event:%s" , conn .conn_id , event )
376- self .sock_conn_map [sock ] = conn
377384 try :
378385 self .select2 .register_event (sock , event , conn )
379386 except Exception as e :
380387 self .xlog .warn ("add_sock_event %s conn:%d e:%r" , sock , conn .conn_id , e )
381388 self .close_sock (sock , str (e ) + "_when_add_sock_event" )
382389 return
383390
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+
384396 if not self .th :
385397 self .th = threading .Thread (target = self .pipe_worker , name = "x_tunnel_pipe_worker" )
386398 self .th .start ()
@@ -438,6 +450,12 @@ def reset_all_connections(self):
438450 self .sock_conn_map = {}
439451 self .select2 = selectors .DefaultSelector ()
440452
453+ def notice_select (self ):
454+ self .xlog .debug ("notice select" )
455+
456+ def read_notify (self ):
457+ self .xlog .debug ("read_notify" )
458+
441459 def pipe_worker (self ):
442460 timeout = 0.001
443461 while self .running :
@@ -453,15 +471,15 @@ def pipe_worker(self):
453471 if has_data :
454472 timeout = 0.01
455473 else :
456- timeout = 3.0
474+ timeout = self . slow_wait
457475
458476 # self.xlog.debug("%s recv select timeout switch to %f", random_id, timeout)
459477 continue
460478 else :
461479 # self.xlog.debug("%s recv select timeout switch to 0.001", random_id)
462480 timeout = 0.001
463481 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 )
465483 if "Invalid argument" in str (e ):
466484 self .reset_all_connections ()
467485 time .sleep (1 )
@@ -471,6 +489,11 @@ def pipe_worker(self):
471489 for key , event in events :
472490 sock = key .fileobj
473491 conn = key .data
492+ if not conn :
493+ self .xlog .debug ("get notice" )
494+ self .read_notify ()
495+ continue
496+
474497 if event & selectors .EVENT_READ :
475498 try :
476499 data = sock .recv (65535 )
0 commit comments