Check-in [fe1f0ecd35]
Overview
Comment:Updated I/O handling to properly deal with errors and passing that error code up the stack
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: fe1f0ecd357d602594593dac7c4bef54ebd12e35
User & Date: rkeene on 2016-12-13 07:42:17
Other Links: manifest | tags
Context
2016-12-13
07:55
Removed an uninitialized read during debugging output and made OutputProc TLS initializations resemble InputProc's version check-in: 7e57900ba3 user: rkeene tags: trunk
07:42
Updated I/O handling to properly deal with errors and passing that error code up the stack check-in: fe1f0ecd35 user: rkeene tags: trunk
07:19
Enhanced support for syscall error checking from BIOs check-in: 538876ebf5 user: rkeene tags: trunk
Changes

Modified tlsIO.c from [48013cc12f] to [3bb908850c].

240
241
242
243
244
245
246


247
248
249
250






251
252
253
254
255
256
257
258
259
260
261
262
263

264
265
266




267
268
269
270

271
272
273
274
275
276
277
240
241
242
243
244
245
246
247
248




249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266

267
268
269
270
271
272
273
274
275
276
277

278
279
280
281
282
283
284
285







+
+
-
-
-
-
+
+
+
+
+
+












-
+



+
+
+
+



-
+







	 */
	ERR_clear_error();
	bytesRead = BIO_read(statePtr->bio, buf, bufSize);
	dprintf("BIO_read -> %d", bytesRead);

	err = SSL_get_error(statePtr->ssl, bytesRead);

#if 0
	if (bytesRead <= 0) {
	if (BIO_should_retry(statePtr->bio)) {
		dprintf("I/O failed, will retry based on EAGAIN");
		*errorCodePtr = EAGAIN;
	}
		if (BIO_should_retry(statePtr->bio)) {
			dprintf("I/O failed, will retry based on EAGAIN");
			*errorCodePtr = EAGAIN;
		}
	}
#endif

	switch (err) {
		case SSL_ERROR_NONE:
			dprintBuffer(buf, bytesRead);
			break;
		case SSL_ERROR_SSL:
			Tls_Error(statePtr, TCLTLS_SSL_ERROR(statePtr->ssl, bytesRead));
			*errorCodePtr = ECONNABORTED;
			break;
		case SSL_ERROR_SYSCALL:
			backingError = ERR_get_error();

			if (backingError == 0 && err == 0) {
			if (backingError == 0 && bytesRead == 0) {
				dprintf("EOF reached")
				*errorCodePtr = 0;
				bytesRead = 0;
			} else if (backingError == 0 && bytesRead == -1) {
				dprintf("I/O error occured (errno = %lu)", (unsigned long) Tcl_GetErrno());
				*errorCodePtr = Tcl_GetErrno();
				bytesRead = -1;
			} else {
				dprintf("I/O error occured (backingError = %lu)", backingError);
				*errorCodePtr = backingError;
				bytesRead = 0;
				bytesRead = -1;
			}

			break;
	}

	dprintf("Input(%d) -> %d [%d]", bufSize, bytesRead, *errorCodePtr);
	return(bytesRead);
292
293
294
295
296
297
298

299
300
301
302
303
304
305
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314







+







 * Side effects:
 *	Writes output on the output device of the channel.
 *
 *-------------------------------------------------------------------
 */

static int TlsOutputProc(ClientData instanceData, CONST char *buf, int toWrite, int *errorCodePtr) {
	unsigned long backingError;
	State *statePtr = (State *) instanceData;
	int written, err;

	*errorCodePtr = 0;

	dprintf("BIO_write(%p, %d)", (void *) statePtr, toWrite);
	dprintBuffer(buf, toWrite);
368
369
370
371
372
373
374








375
376
377








378
379
380
381
382
383
384
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406







+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+







			dprintf(" write X BLOCK");
			break;
		case SSL_ERROR_ZERO_RETURN:
			dprintf(" closed");
			written = 0;
			break;
		case SSL_ERROR_SYSCALL:
			backingError = ERR_get_error();

			if (backingError == 0 && written == 0) {
				dprintf("EOF reached")
				*errorCodePtr = 0;
				written = 0;
			} else if (backingError == 0 && written == -1) {
				dprintf("I/O error occured (errno = %lu)", (unsigned long) Tcl_GetErrno());
			*errorCodePtr = Tcl_GetErrno();
			dprintf(" [%d] syscall errr: %d", written, *errorCodePtr);
			written = -1;
				*errorCodePtr = Tcl_GetErrno();
				written = -1;
			} else {
				dprintf("I/O error occured (backingError = %lu)", backingError);
				*errorCodePtr = backingError;
				written = -1;
			}

			break;
		case SSL_ERROR_SSL:
			Tls_Error(statePtr, TCLTLS_SSL_ERROR(statePtr->ssl, written));
			*errorCodePtr = ECONNABORTED;
			written = -1;
			break;
		default: