 
 : maybe-handshake ( ssl-handle -- )
     dup connected>> [ drop ] [
-        [ [ do-ssl-accept ] with-timeout ]
-        [ t swap connected<< ] bi
+        dup terminated>> [
+            drop
+        ] [
+            [ [ do-ssl-accept ] with-timeout ]
+            [ t swap connected<< ] bi
+        ] if
     ] if ;
 
 ! Input ports

        tri
    ] with-destructors ;

TUPLE: ssl-handle < disposable file handle connected ;

SYMBOL: default-secure-context


    handle ;

: ssl-error-syscall ( ssl-handle -- event/f )
    f >>connected
    t >>terminated drop
    ERR_get_error {
        { -1 [
            errno { [ ECONNRESET = ] [ EPIPE = ] } 1||
