 
 SYMBOL: remote-address
 
-GENERIC: handle-client* ( server -- )
+GENERIC: handle-client* ( threaded-server -- )
 
 <PRIVATE
 

        if*
    ] [ accept-loop ] bi ; inline recursive

: started-accept-loop ( server -- )
    threaded-server get
    [ sockets>> push ] [ ready>> raise-flag ] bi ;


: thread-name ( server-name addrspec -- string )
    unparse " connection from " swap 3append ;

: accept-connection ( threaded-server -- )
    [ accept ] [ addr>> ] bi
    [ '[ , , , handle-client ] ]
    [ drop threaded-server get name>> swap thread-name ] 2bi
    spawn drop ;

: accept-loop ( threaded-server -- )
    [
        threaded-server get semaphore>>
        [ [ accept-connection ] with-semaphore ]
