Check-in [b5ba86f2be]
Overview
Comment:Fixed pass-through to fetch file descriptor using a pointer
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wip-fix-io-layer
Files: files | file ages | folders
SHA1: b5ba86f2bea2cd651a4a8553b5317b7ee10207a0
User & Date: rkeene on 2016-12-11 20:05:54
Other Links: branch diff | manifest | tags
Context
2016-12-11
21:22
Rewrote state engine for OpenSSL connection establishment to be more easily reasoned about check-in: 77e904c4e2 user: rkeene tags: wip-fix-io-layer
20:05
Fixed pass-through to fetch file descriptor using a pointer check-in: b5ba86f2be user: rkeene tags: wip-fix-io-layer
19:20
Updated to support optionally enabling/disabling a faster path for talking to the underlying channel check-in: d25ae3c232 user: rkeene tags: wip-fix-io-layer
Changes

Modified tlsBIO.c from [f8c02fc8c8] to [f1da770d9f].

39
40
41
42
43
44
45

46
47
48
49
50
51
52
static int BioFree  _ANSI_ARGS_((BIO *h));

BIO *BIO_new_tcl(State *statePtr, int flags) {
	BIO *bio;
	Tcl_Channel parentChannel;
	const Tcl_ChannelType *parentChannelType;
	static BIO_METHOD *BioMethods = NULL;

	int parentChannelFdIn, parentChannelFdOut, parentChannelFd;
	int validParentChannelFd;
	int tclGetChannelHandleRet;

	dprintf("BIO_new_tcl() called");

	if (BioMethods == NULL) {







>







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
static int BioFree  _ANSI_ARGS_((BIO *h));

BIO *BIO_new_tcl(State *statePtr, int flags) {
	BIO *bio;
	Tcl_Channel parentChannel;
	const Tcl_ChannelType *parentChannelType;
	static BIO_METHOD *BioMethods = NULL;
	void *parentChannelFdIn_p, *parentChannelFdOut_p;
	int parentChannelFdIn, parentChannelFdOut, parentChannelFd;
	int validParentChannelFd;
	int tclGetChannelHandleRet;

	dprintf("BIO_new_tcl() called");

	if (BioMethods == NULL) {
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85


86
87
88
89
90
91
92
	/*
	 * If the channel can be mapped back to a file descriptor, just use the file descriptor
	 * with the SSL library since it will likely be optimized for this.
	 */
	parentChannel = Tls_GetParent(statePtr);
	parentChannelType = Tcl_GetChannelType(parentChannel);

	/* If we do not get the channel name here, we segfault later :-( */
	dprintf("Channel Name is valid: %s", Tcl_GetChannelName(statePtr->self));
	dprintf("Parent Channel Name is valid: %s", Tcl_GetChannelName(parentChannel));

	validParentChannelFd = 0;
	if (strcmp(parentChannelType->typeName, "tcp") == 0) {
		tclGetChannelHandleRet = Tcl_GetChannelHandle(parentChannel, TCL_READABLE, (ClientData) &parentChannelFdIn);
		if (tclGetChannelHandleRet == TCL_OK) {
			tclGetChannelHandleRet = Tcl_GetChannelHandle(parentChannel, TCL_WRITABLE, (ClientData) &parentChannelFdOut);
			if (tclGetChannelHandleRet == TCL_OK) {


				if (parentChannelFdIn == parentChannelFdOut) {
					parentChannelFd = parentChannelFdIn;
					validParentChannelFd = 1;
				}
			}
		}
	}







<
<
<
<


|

|

>
>







70
71
72
73
74
75
76




77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
	/*
	 * If the channel can be mapped back to a file descriptor, just use the file descriptor
	 * with the SSL library since it will likely be optimized for this.
	 */
	parentChannel = Tls_GetParent(statePtr);
	parentChannelType = Tcl_GetChannelType(parentChannel);





	validParentChannelFd = 0;
	if (strcmp(parentChannelType->typeName, "tcp") == 0) {
		tclGetChannelHandleRet = Tcl_GetChannelHandle(parentChannel, TCL_READABLE, (ClientData) &parentChannelFdIn_p);
		if (tclGetChannelHandleRet == TCL_OK) {
			tclGetChannelHandleRet = Tcl_GetChannelHandle(parentChannel, TCL_WRITABLE, (ClientData) &parentChannelFdOut_p);
			if (tclGetChannelHandleRet == TCL_OK) {
				parentChannelFdIn = PTR2INT(parentChannelFdIn_p);
				parentChannelFdOut = PTR2INT(parentChannelFdOut_p);
				if (parentChannelFdIn == parentChannelFdOut) {
					parentChannelFd = parentChannelFdIn;
					validParentChannelFd = 1;
				}
			}
		}
	}

Modified tlsInt.h from [687b53b5c5] to [5bf94ee7f7].

17
18
19
20
21
22
23

24
25
26
27
28
29
30
 */
#ifndef _TLSINT_H
#define _TLSINT_H

#include "tls.h"
#include <errno.h>
#include <string.h>


#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <wincrypt.h> /* OpenSSL needs this on Windows */
#endif








>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 */
#ifndef _TLSINT_H
#define _TLSINT_H

#include "tls.h"
#include <errno.h>
#include <string.h>
#include <stdint.h>

#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <wincrypt.h> /* OpenSSL needs this on Windows */
#endif

160
161
162
163
164
165
166
167


168
Tcl_Obj         *Tls_NewX509Obj(Tcl_Interp *interp, X509 *cert);
void            Tls_Error(State *statePtr, char *msg);
void            Tls_Free(char *blockPtr);
void            Tls_Clean(State *statePtr);
int             Tls_WaitForConnect(State *statePtr, int *errorCodePtr);

BIO             *BIO_new_tcl(State* statePtr, int flags);



#endif /* _TLSINT_H */








>
>

161
162
163
164
165
166
167
168
169
170
171
Tcl_Obj         *Tls_NewX509Obj(Tcl_Interp *interp, X509 *cert);
void            Tls_Error(State *statePtr, char *msg);
void            Tls_Free(char *blockPtr);
void            Tls_Clean(State *statePtr);
int             Tls_WaitForConnect(State *statePtr, int *errorCodePtr);

BIO             *BIO_new_tcl(State* statePtr, int flags);

#define PTR2INT(x) ((int) ((intptr_t) (x)))

#endif /* _TLSINT_H */