Check-in [b29663e789]
Bounty program for improvements to Tcl and certain Tcl packages.
Overview
Comment:Moved ChannelHandler to the main channel instead of using Tls_GetParent and registering the handler with the dummy, or stacked channel. Eliminated call to Tcl_NotifyChannel from the WatchProc
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b29663e78915db62f1fe106e51982e71fa1cab85
User & Date: welch on 2000-05-31 21:24:24
Other Links: manifest | tags
Context
2000-06-01
19:26
* tlsIO.c: Restore the previous version. Fixed the CloseProc so it unregisters the channel handler on the superceded channel instead of the upper channel. Also removed the call to Tcl_NotifyChannel in the ChannelHandler because this will result in an infinite loop if data is ever buffered in the BIO structure. [Bug: 5623] check-in: b86c814390 user: stanton tags: trunk
2000-05-31
21:24
Moved ChannelHandler to the main channel instead of using Tls_GetParent and registering the handler with the dummy, or stacked channel. Eliminated call to Tcl_NotifyChannel from the WatchProc check-in: b29663e789 user: welch tags: trunk
2000-05-30
22:18
changed copyright notice from Scriptics to Ajuba check-in: 17f61c8277 user: aborr tags: trunk
Changes

Added ChangeLog version [49cd482fb3].




















>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
2000-05-31  Brent Welch <[email protected]>

	* tls.c: Change the ChannelHandler to be registered on the main
	channel as oppsed to the "parent", or superceeded, channel.  This
	is because the socket driver notifies the main channel, and there are
	times with the main channel gets closed, but the superceded one
	is not yet closed.  If the channel handler gets triggered in this
	half-open state it is associated with the superceeded channedl, but
	uses its private pointer to the main channel, which is mostly destroyed.
	* Eliminated the redundant call to Tcl_NotifyChannel from TlsWatchProc

Modified tlsIO.c from [e2f15d6a74] to [3d8ca23169].

1
2
3
4
5
6
7
8
9
10
11
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
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
407
408
409
410
...
477
478
479
480
481
482
483





484

485
486
487
488
489
490
491
/*
 * Copyright (C) 1997-2000 Matt Newman <[email protected]>
 *
 * $Header: /home/rkeene/tmp/cvs2fossil/../tcltls/tls/tls/tlsIO.c,v 1.2 2000/01/20 01:52:18 aborr Exp $
 *
 * TLS (aka SSL) Channel - can be layered on any bi-directional
 * Tcl_Channel (Note: Requires Trf Core Patch)
 *
 * This was built from scratch based upon observation of OpenSSL 0.9.2B
 *
 * Addition credit is due for Andreas Kupries ([email protected]), for
................................................................................
 */
static int
CloseProc(ClientData instanceData,	/* The socket to close. */
             Tcl_Interp *interp)	/* For error reporting - unused. */
{
    State *statePtr = (State *) instanceData;
#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION < 2
    Tcl_Channel parent = Tls_GetParent(statePtr);
#else
    Tcl_Channel parent = statePtr->self; /* 'self' already refers to our parent */
#endif

    dprintf(stderr,"\nCloseProc(0x%x)", statePtr);
    /*
     * Remove event handler to underlying channel, this could
     * be because we are closing for real, or being "unstacked".
     */

    Tcl_DeleteChannelHandler( parent,
	ChannelHandler, (ClientData) statePtr);

    if (statePtr->timer != (Tcl_TimerToken)NULL) {
	Tcl_DeleteTimerHandler (statePtr->timer);
	statePtr->timer = (Tcl_TimerToken)NULL;
    }

................................................................................
static void
WatchProc(ClientData instanceData,	/* The socket state. */
             int mask)			/* Events of interest; an OR-ed
                                         * combination of TCL_READABLE,
                                         * TCL_WRITABLE and TCL_EXCEPTION. */
{
    State *statePtr = (State *) instanceData;













    if (mask == statePtr->watchMask)
	return;

    if (statePtr->watchMask) {
	/*
	 * Remove event handler to underlying channel, this could
	 * be because we are closing for real, or being "unstacked".
	 */
	Tcl_DeleteChannelHandler( Tls_GetParent(statePtr), ChannelHandler, (ClientData) statePtr);
    }
    statePtr->watchMask = mask;
    if (statePtr->watchMask) {
	/* Setup active monitor for events on underlying Channel */
	Tcl_CreateChannelHandler( Tls_GetParent(statePtr), statePtr->watchMask,
				ChannelHandler, (ClientData) statePtr);
    }
}
 
/*
 *-------------------------------------------------------------------
 *
................................................................................
    mask = 0;
    if (BIO_wpending(statePtr->bio)) {
	mask |= TCL_WRITABLE;
    }
    if (BIO_pending(statePtr->bio)) {
	mask |= TCL_READABLE;
    }





    Tcl_NotifyChannel(statePtr->self, mask);


    if (statePtr->timer != (Tcl_TimerToken)NULL) {
	Tcl_DeleteTimerHandler(statePtr->timer);
	statePtr->timer = (Tcl_TimerToken)NULL;
    }
    if ((mask & TCL_READABLE) && Tcl_InputBuffered (statePtr->self) > 0) {
	/*


|







 







|

|




|



|







 







>
>
>
>
>
>
>
>
>
>
>
>






|


|




|







 







>
>
>
>
>

>







1
2
3
4
5
6
7
8
9
10
11
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
...
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
/*
 * Copyright (C) 1997-2000 Matt Newman <[email protected]>
 *
 * $Header: /home/rkeene/tmp/cvs2fossil/../tcltls/tls/tls/tlsIO.c,v 1.3 2000/05/31 21:24:24 welch Exp $
 *
 * TLS (aka SSL) Channel - can be layered on any bi-directional
 * Tcl_Channel (Note: Requires Trf Core Patch)
 *
 * This was built from scratch based upon observation of OpenSSL 0.9.2B
 *
 * Addition credit is due for Andreas Kupries ([email protected]), for
................................................................................
 */
static int
CloseProc(ClientData instanceData,	/* The socket to close. */
             Tcl_Interp *interp)	/* For error reporting - unused. */
{
    State *statePtr = (State *) instanceData;
#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION < 2
    Tcl_Channel chanPtr = Tls_GetParent(statePtr);
#else
    Tcl_Channel chanPtr = statePtr->self; /* 'self' already refers to our parent */
#endif

    dprintf(stderr,"\nCloseProc(0x%x)", statePtr);
    /*
     * Remove event handler to the channel, this could
     * be because we are closing for real, or being "unstacked".
     */

    Tcl_DeleteChannelHandler( chanPtr,
	ChannelHandler, (ClientData) statePtr);

    if (statePtr->timer != (Tcl_TimerToken)NULL) {
	Tcl_DeleteTimerHandler (statePtr->timer);
	statePtr->timer = (Tcl_TimerToken)NULL;
    }

................................................................................
static void
WatchProc(ClientData instanceData,	/* The socket state. */
             int mask)			/* Events of interest; an OR-ed
                                         * combination of TCL_READABLE,
                                         * TCL_WRITABLE and TCL_EXCEPTION. */
{
    State *statePtr = (State *) instanceData;
#if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION < 2
    Tcl_Channel chanPtr = Tls_GetParent(statePtr);
#else
    /*
     * We set up the channel handler on the main channel, not the
     * hidden channel.  The main channel gets notified by the underlying
     * drivers, so we don't need to put the handler anywhere else.
     * Also, because our state refers to the main channel, it is only
     * safe to have our handler registered on that same channel.
     */
    Tcl_Channel chanPtr = statePtr->self;
#endif

    if (mask == statePtr->watchMask)
	return;

    if (statePtr->watchMask) {
	/*
	 * Remove event handler to the channel, this could
	 * be because we are closing for real, or being "unstacked".
	 */
	Tcl_DeleteChannelHandler( chanPtr, ChannelHandler, (ClientData) statePtr);
    }
    statePtr->watchMask = mask;
    if (statePtr->watchMask) {
	/* Setup active monitor for events on underlying Channel */
	Tcl_CreateChannelHandler( chanPtr, statePtr->watchMask,
				ChannelHandler, (ClientData) statePtr);
    }
}
 
/*
 *-------------------------------------------------------------------
 *
................................................................................
    mask = 0;
    if (BIO_wpending(statePtr->bio)) {
	mask |= TCL_WRITABLE;
    }
    if (BIO_pending(statePtr->bio)) {
	mask |= TCL_READABLE;
    }
#ifdef notdef
    /*
     * Tcl_NotifyChannel already runs through the list of stacked
     * channels doing chained notifications.  No need to do this.
     */
    Tcl_NotifyChannel(statePtr->self, mask);
#endif

    if (statePtr->timer != (Tcl_TimerToken)NULL) {
	Tcl_DeleteTimerHandler(statePtr->timer);
	statePtr->timer = (Tcl_TimerToken)NULL;
    }
    if ((mask & TCL_READABLE) && Tcl_InputBuffered (statePtr->self) > 0) {
	/*