         ] }
         ! https://stackoverflow.com/questions/13686398/ssl-read-failing-with-ssl-error-syscall-error
         ! 0 means EOF
-        { 0 [ premature-close-error f ] }
+        { 0 [ f ] }
     } case ;
 
 : check-ssl-error ( ssl-handle ret -- event/f )

    ] if* ;

M: ssl-handle drain
    dup maybe-handshake [ buffer>> ] dip do-ssl-write ;

! Connect

        dup 0 > [ swap buffer+ ] [ 2drop ] if f
    ] if* ;

: throw-if-terminated ( ssl-handle -- ssl-handle )
    dup terminated>> [ premature-close-error ] when ;

M: ssl-handle refill
    throw-if-terminated
    dup maybe-handshake [ buffer>> ] dip do-ssl-read ;

! Output ports
