Index: generic/tlsIO.c ================================================================== --- generic/tlsIO.c +++ generic/tlsIO.c @@ -35,12 +35,13 @@ * * TlsBlockModeProc -- * * This procedure is invoked by the generic IO level * to set blocking and nonblocking modes + * * Results: - * 0 if successful, errno when failed. + * 0 if successful or POSIX error code if failed. * * Side effects: * Sets the device into blocking or nonblocking mode. * *------------------------------------------------------------------- @@ -66,11 +67,11 @@ * is closed. * * Note: we leave the underlying socket alone, is this right? * * Results: - * 0 if successful, the value of Tcl_GetErrno() if failed. + * 0 if successful or POSIX error code if failed. * * Side effects: * Closes the socket of the channel. * *------------------------------------------------------------------- @@ -86,27 +87,34 @@ /* Interp is unused. */ interp = interp; } -static int TlsCloseProc2(ClientData instanceData, Tcl_Interp *interp, int flags) { +static int TlsCloseProc2(ClientData instanceData, /* The socket state. */ + Tcl_Interp *interp, /* For errors - can be NULL. */ + int flags) /* Flags to close read and/or write side of channel */ +{ + State *statePtr = (State *) instanceData; + + dprintf("TlsCloseProc2(%p)", (void *) statePtr); + if ((flags & (TCL_CLOSE_READ|TCL_CLOSE_WRITE)) == 0) { return TlsCloseProc(instanceData, interp); } return EINVAL; } /* *------------------------------------------------------* * - * Tls_WaitForConnect -- + * Tls_WaitForConnect -- * - * Side effects: - * Issues SSL_accept or SSL_connect + * Result: + * 0 if successful, -1 if failed. * - * Result: - * None. + * Side effects: + * Issues SSL_accept or SSL_connect * *------------------------------------------------------* */ int Tls_WaitForConnect(State *statePtr, int *errorCodePtr, int handshakeFailureIsPermanent) { unsigned long backingError; @@ -277,13 +285,12 @@ * * This procedure is invoked by the generic IO level * to read input from a SSL socket based channel. * * Results: - * The number of bytes read is returned or -1 on error. An output - * argument contains the POSIX error code on error, or zero if no - * error occurred. + * Returns the number of bytes read or -1 on error. Sets errorCodePtr + * to a POSIX error code if an error occurred, or 0 if none. * * Side effects: * Reads input from the input device of the channel. * *------------------------------------------------------------------- @@ -411,12 +418,12 @@ * * This procedure is invoked by the generic IO level * to write output to a SSL socket based channel. * * Results: - * The number of bytes written is returned. An output argument is - * set to a POSIX error code if an error occurred, or zero. + * Returns the number of bytes written or -1 on error. Sets errorCodePtr + * to a POSIX error code if an error occurred, or 0 if none. * * Side effects: * Writes output on the output device of the channel. * *------------------------------------------------------------------- @@ -554,20 +561,18 @@ /* *------------------------------------------------------------------- * * TlsSetOptionProc -- * - * Computes an option value for a SSL socket based channel, or a + * Sets an option value for a SSL socket based channel, or a * list of all options and their values. * * Results: - * A standard Tcl result. The value of the specified option or a - * list of all options and their values is returned in the - * supplied DString. + * TCL_OK if successful or TCL_ERROR if failed. * * Side effects: - * None. + * Updates channel option to new value. * *------------------------------------------------------------------- */ static int TlsSetOptionProc(ClientData instanceData, /* Socket state. */ @@ -591,24 +596,24 @@ return TCL_OK; } /* * Request for a specific option has to fail, we don't have any. */ - return TCL_ERROR; + return Tcl_BadChannelOption(interp, optionName, ""); } /* *------------------------------------------------------------------- * * TlsGetOptionProc -- * - * Computes an option value for a SSL socket based channel, or a + * Gets an option value for a SSL socket based channel, or a * list of all options and their values. * * Results: * A standard Tcl result. The value of the specified option or a - * list of all options and their values is returned in the + * list of all options and their values is returned in the * supplied DString. * * Side effects: * None. * @@ -617,30 +622,30 @@ static int TlsGetOptionProc(ClientData instanceData, /* Socket state. */ Tcl_Interp *interp, /* For errors - can be NULL. */ const char *optionName, /* Name of the option to retrieve the value for, or * NULL to get all options and their values. */ - Tcl_DString *dsPtr) /* Where to store the computed value initialized by caller. */ + Tcl_DString *optionValue) /* Where to store the computed value initialized by caller. */ { State *statePtr = (State *) instanceData; Tcl_Channel downChan = Tls_GetParent(statePtr, TLS_TCL_FASTPATH); Tcl_DriverGetOptionProc *getOptionProc; getOptionProc = Tcl_ChannelGetOptionProc(Tcl_GetChannelType(downChan)); if (getOptionProc != NULL) { - return (*getOptionProc)(Tcl_GetChannelInstanceData(downChan), interp, optionName, dsPtr); + return (*getOptionProc)(Tcl_GetChannelInstanceData(downChan), interp, optionName, optionValue); } else if (optionName == (char*) NULL) { /* * Request is query for all options, this is ok. */ return TCL_OK; } /* * Request for a specific option has to fail, we don't have any. */ - return TCL_ERROR; + return Tcl_BadChannelOption(interp, optionName, ""); } /* *------------------------------------------------------------------- * @@ -657,12 +662,12 @@ * *------------------------------------------------------------------- */ static void TlsWatchProc(ClientData instanceData, /* The socket state. */ - int mask) /* Events of interest; an OR-ed combination of - * TCL_READABLE, TCL_WRITABLE and TCL_EXCEPTION. */ + int mask) /* Events of interest; an OR-ed combination of + * TCL_READABLE, TCL_WRITABLE and TCL_EXCEPTION. */ { Tcl_Channel downChan; State *statePtr = (State *) instanceData; dprintf("TlsWatchProc(0x%x)", mask); @@ -708,16 +713,16 @@ statePtr->timer = (Tcl_TimerToken) NULL; } if ((mask & TCL_READABLE) && ((Tcl_InputBuffered(statePtr->self) > 0) || (BIO_ctrl_pending(statePtr->bio) > 0))) { - /* - * There is interest in readable events and we actually have - * data waiting, so generate a timer to flush that. - */ - dprintf("Creating a new timer since data appears to be waiting"); - statePtr->timer = Tcl_CreateTimerHandler(TLS_TCL_DELAY, TlsChannelHandlerTimer, (ClientData) statePtr); + /* + * There is interest in readable events and we actually have + * data waiting, so generate a timer to flush that. + */ + dprintf("Creating a new timer since data appears to be waiting"); + statePtr->timer = Tcl_CreateTimerHandler(TLS_TCL_DELAY, TlsChannelHandlerTimer, (ClientData) statePtr); } } /* *------------------------------------------------------------------- @@ -726,18 +731,21 @@ * * Called from Tcl_GetChannelFile to retrieve o/s file handler * from the SSL socket based channel. * * Results: - * The appropriate Tcl_File or NULL if not present. + * The appropriate Tcl_File handle or NULL if none. * * Side effects: * None. * *------------------------------------------------------------------- */ -static int TlsGetHandleProc(ClientData instanceData, int direction, ClientData *handlePtr) { +static int TlsGetHandleProc(ClientData instanceData, /* Socket state. */ + int direction, /* TCL_READABLE or TCL_WRITABLE */ + ClientData *handlePtr) /* Handle associated with the channel */ +{ State *statePtr = (State *) instanceData; return(Tcl_GetChannelHandle(Tls_GetParent(statePtr, TLS_TCL_FASTPATH), direction, handlePtr)); } @@ -748,18 +756,21 @@ * * Handler called by Tcl to inform us of activity * on the underlying channel. * * Results: - * None. + * Type of event or 0 if failed * * Side effects: * May process the incoming event by itself. * *------------------------------------------------------------------- */ -static int TlsNotifyProc(ClientData instanceData, int mask) { +static int TlsNotifyProc(ClientData instanceData, /* Socket state. */ + int mask) /* type of event that occurred: + * OR-ed combination of TCL_READABLE or TCL_WRITABLE */ +{ State *statePtr = (State *) instanceData; int errorCode; /* * An event occurred in the underlying channel. This @@ -821,11 +832,11 @@ * None. * *------------------------------------------------------* */ static void -TlsChannelHandler (ClientData clientData, int mask) { +TlsChannelHandler(ClientData clientData, int mask) { State *statePtr = (State *) clientData; dprintf("HANDLER(0x%x)", mask); Tcl_Preserve((ClientData)statePtr);