Index: generic/tlsIO.c ================================================================== --- generic/tlsIO.c +++ generic/tlsIO.c @@ -77,16 +77,15 @@ static int TlsCloseProc(ClientData instanceData, Tcl_Interp *interp) { State *statePtr = (State *) instanceData; dprintf("TlsCloseProc(%p)", (void *) statePtr); - /* Flush any pending data */ - /* Send shutdown notification. Will return 0 while in process, then 1 when complete. */ /* Closes the write direction of the connection; the read direction is closed by the peer. */ /* Does not affect socket state. Don't call after fatal error. */ if (statePtr->ssl != NULL && !(statePtr->flags & TLS_TCL_HANDSHAKE_FAILED)) { + BIO_flush(statePtr->bio); SSL_shutdown(statePtr->ssl); } /* Tls_Free calls Tls_Clean */ Tcl_EventuallyFree((ClientData)statePtr, Tls_Free); Index: tests/tlsIO.test ================================================================== --- tests/tlsIO.test +++ tests/tlsIO.test @@ -1142,15 +1142,18 @@ localhost 8831] # This differs from socket-9.1 in that both sides need to be # non-blocking because of TLS' required handshake fconfigure $c -blocking 0 puts -nonewline $c 01234567890123456789012345678901234567890123456789 - close $c + flush $c + set timer2 [after 2000 [list close $c]] set timer [after 10000 "set done timed_out"] vwait done after cancel $timer - close $s + after cancel $timer2 + catch {close $c} + catch {close $s} list $spurious $len } {0 50} test tlsIO-9.2 {testing async write, fileevents, flush on close} {socket} { set firstblock [string repeat a 31]