diff -ur v3/sock_ut.py v4/sock_ut.py --- v3/sock_ut.py 2021-06-24 21:26:04.000000000 +0900 +++ v4/sock_ut.py 2021-06-28 19:46:14.000000000 +0900 @@ -48,6 +48,10 @@ bt = recv_bt( sc ) return bt.decode( 'utf-8' ) +def recv_str_all( sc ): + bt = recv_bt_all( sc ) + return bt.decode( 'utf-8' ) + def pipe_loop( sc_from, sc_to ): while True: bt = recv_bt( sc_from ) @@ -181,7 +185,7 @@ return None return ss -def accept_inner( ss ): +def accept_recv_ping( ss ): s = recv_str( ss ) if not s: return None @@ -193,6 +197,20 @@ if d.get( 'id' ) == 'ping': return 'ping' + return ( s, d ) + +def accept_recv( ss ): + r = None + while True: + r = accept_recv_ping( ss ) + if r != 'ping': + break + return r # None or ( s, d ) + +def accept_conn( r ): + if not r: + return None + ( s, d ) = r port = int( d.get( 'port' ) ) cs = port_conn( port ) if not send_str( cs, s ): @@ -205,13 +223,8 @@ return cs def accept( ss ): - cs = None - while True: - cs = accept_inner( ss ) - if cs != 'ping': - break - #dbg.out( 'accept ping' ) - return cs + r = accept_recv( ss ) + return accept_conn( r ) def srv_loop( port, name, th_func ): ss = server( port, name ) @@ -223,6 +236,7 @@ break th = thr.th_new( th_func, ( cs, ) ) thr.ths.start( th ) + ss.close() def srv_func_new( cb ):