Index: tlsIO.c
==================================================================
--- tlsIO.c
+++ tlsIO.c
@@ -213,20 +213,21 @@
 	}
 
 	dprintf("Calling Tls_WaitForConnect");
 	tlsConnect = Tls_WaitForConnect(statePtr, errorCodePtr);
 	if (tlsConnect < 0) {
-		dprintf("Got an error (bytesRead = %i)", bytesRead);
+		dprintf("Got an error waiting to connect (tlsConnect = %i, *errorCodePtr = %i)", tlsConnect, *errorCodePtr);
 
+		bytesRead = -1;
 		if (*errorCodePtr == ECONNRESET) {
 			dprintf("Got connection reset");
 			/* Soft EOF */
 			*errorCodePtr = 0;
 			bytesRead = 0;
 		}
 
-		return(0);
+		return(bytesRead);
 	}
 
 	/*
 	 * We need to clear the SSL error stack now because we sometimes reach
 	 * this function with leftover errors in the stack.  If BIO_read
@@ -305,10 +306,11 @@
 
 static int TlsOutputProc(ClientData instanceData, CONST char *buf, int toWrite, int *errorCodePtr) {
 	unsigned long backingError;
 	State *statePtr = (State *) instanceData;
 	int written, err;
+	int tlsConnect;
 
 	*errorCodePtr = 0;
 
 	dprintf("BIO_write(%p, %d)", (void *) statePtr, toWrite);
 	dprintBuffer(buf, toWrite);
@@ -319,15 +321,23 @@
 		*errorCodePtr = EAGAIN;
 		return(-1);
 	}
 
 	dprintf("Calling Tls_WaitForConnect");
-	written = Tls_WaitForConnect(statePtr, errorCodePtr);
-	if (written < 0) {
-		dprintf("Tls_WaitForConnect returned %i (err = %i)", written, *errorCodePtr);
+	tlsConnect = Tls_WaitForConnect(statePtr, errorCodePtr);
+	if (tlsConnect < 0) {
+		dprintf("Got an error waiting to connect (tlsConnect = %i, *errorCodePtr = %i)", tlsConnect, *errorCodePtr);
 
-		return(-1);
+		written = -1;
+		if (*errorCodePtr == ECONNRESET) {
+			dprintf("Got connection reset");
+			/* Soft EOF */
+			*errorCodePtr = 0;
+			written = 0;
+		}
+
+		return(written);
 	}
 
 	if (toWrite == 0) {
 		dprintf("zero-write");
 		err = BIO_flush(statePtr->bio);