@@ -354,10 +354,11 @@ bytesRead = 0; } goto input; } } + if (statePtr->flags & TLS_TCL_INIT) { statePtr->flags &= ~(TLS_TCL_INIT); } /* * We need to clear the SSL error stack now because we sometimes reach @@ -436,10 +437,12 @@ } if (!SSL_is_init_finished(statePtr->ssl)) { written = Tls_WaitForConnect(statePtr, errorCodePtr); if (written <= 0) { + dprintf("Tls_WaitForConnect returned %i (err = %i)", written, *errorCodePtr); + goto output; } } if (statePtr->flags & TLS_TCL_INIT) { statePtr->flags &= ~(TLS_TCL_INIT); @@ -907,21 +910,25 @@ } for (;;) { /* Not initialized yet! */ if (statePtr->flags & TLS_TCL_SERVER) { + dprintf("Calling SSL_accept()"); err = SSL_accept(statePtr->ssl); } else { + dprintf("Calling SSL_connect()"); err = SSL_connect(statePtr->ssl); } + /*SSL_write(statePtr->ssl, (char*)&err, 0); HACK!!! */ if (err > 0) { + dprintf("That seems to have gone okay"); BIO_flush(statePtr->bio); - } - - if (err <= 0) { + } else { int rc = SSL_get_error(statePtr->ssl, err); + + dprintf("Got error: %i (rc = %i)", err, rc); if (rc == SSL_ERROR_SSL) { Tls_Error(statePtr, (char *)ERR_reason_error_string(ERR_get_error())); statePtr->flags |= TLS_TCL_HANDSHAKE_FAILED; @@ -935,10 +942,12 @@ } else { continue; } } else if (err == 0) { if (Tcl_Eof(statePtr->self)) { + dprintf("Error = 0 and EOF is set, returning with 0"); + return 0; } dprintf("CR! "); *errorCodePtr = ECONNRESET; return -1;