@@ -387,10 +387,17 @@ if (statePtr->flags & TLS_TCL_CALLBACK) { /* don't process any bytes while verify callback is running */ dprintf("Callback is running, reading 0 bytes"); return(0); } + + if (statePtr->flags & TLS_TCL_EOF) { + dprintf("Asked to read after reaching EOF, we are treating this as fatal."); + bytesRead = 0; + *errorCodePtr = ECONNRESET; + return(bytesRead); + } dprintf("Calling Tls_WaitForConnect"); tlsConnect = Tls_WaitForConnect(statePtr, errorCodePtr, 0); if (tlsConnect < 0) { dprintf("Got an error waiting to connect (tlsConnect = %i, *errorCodePtr = %i)", tlsConnect, *errorCodePtr); @@ -476,10 +483,16 @@ dprintf("Unknown error (err = %i), mapping to EOF", err); *errorCodePtr = 0; bytesRead = 0; break; } + + if (bufSize != 0 && bytesRead == 0 && *errorCodePtr == 0) { + dprintf("Detected EOF, setting the EOF flag"); + statePtr->flags |= TLS_TCL_EOF; + *errorCodePtr = ECONNRESET; + } dprintf("Input(%d) -> %d [%d]", bufSize, bytesRead, *errorCodePtr); return(bytesRead); } @@ -519,11 +532,11 @@ return(-1); } if (statePtr->flags & TLS_TCL_EOF) { dprintf("Asked to write after reaching EOF, we are treating this as fatal."); - written = -1; + written = 0; *errorCodePtr = ECONNRESET; return(written); } dprintf("Calling Tls_WaitForConnect"); @@ -533,11 +546,11 @@ written = -1; if (*errorCodePtr == ECONNRESET) { dprintf("Got connection reset (setting EOF flag)"); /* Soft EOF */ - *errorCodePtr = 0; + *errorCodePtr = ECONNRESET; written = 0; statePtr->flags |= TLS_TCL_EOF; } return(written); @@ -627,10 +640,11 @@ } if (toWrite != 0 && written == 0 && *errorCodePtr == 0) { dprintf("Detected EOF, setting the EOF flag"); statePtr->flags |= TLS_TCL_EOF; + *errorCodePtr = ECONNRESET; } dprintf("Output(%d) -> %d", toWrite, written); return(written); }