Diff
Not logged in

Differences From Artifact [6826311e7c]:

To Artifact [f56771120f]:


114
115
116
117
118
119
120

121
122
123
124
125
126
127

#define SOCKET_BUFSIZE	4096

/*
 * Static routines for this file:
 */


static int		TcpConnect(Tcl_Interp *interp, TcpState *state);
static void		TcpAccept(ClientData data, int mask);
static int		TcpBlockModeProc(ClientData data, int mode);
static int		TcpCloseProc(ClientData instanceData,
			    Tcl_Interp *interp);
static int		TcpClose2Proc(ClientData instanceData,
			    Tcl_Interp *interp, int flags);







>







114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

#define SOCKET_BUFSIZE	4096

/*
 * Static routines for this file:
 */

static void		TcpAsyncCallback(ClientData clientData, int mask);
static int		TcpConnect(Tcl_Interp *interp, TcpState *state);
static void		TcpAccept(ClientData data, int mask);
static int		TcpBlockModeProc(ClientData data, int mode);
static int		TcpCloseProc(ClientData instanceData,
			    Tcl_Interp *interp);
static int		TcpClose2Proc(ClientData instanceData,
			    Tcl_Interp *interp, int flags);
1023
1024
1025
1026
1027
1028
1029


























1030
1031
1032
1033
1034
1035
1036
    if (GOT_BITS(statePtr->flags, TCP_ASYNC_PENDING)) {
        /*
         * Async sockets use a FileHandler internally while connecting, so we
         * need to cache this request until the connection has succeeded.
         */

        statePtr->filehandlers = mask;


























    } else if (mask) {

	/*
	 * Whether it is a bug or feature or otherwise, it is a fact of life
	 * that on at least some Linux kernels select() fails to report that a
	 * socket file descriptor is writable when the other end of the socket
	 * is closed.  This is in contrast to the guarantees Tcl makes that







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







1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
    if (GOT_BITS(statePtr->flags, TCP_ASYNC_PENDING)) {
        /*
         * Async sockets use a FileHandler internally while connecting, so we
         * need to cache this request until the connection has succeeded.
         */

        statePtr->filehandlers = mask;

	/*
	 * Remove the FileHandler if the socket is not managed by any thread
	 * Otherwise the handler is likely to run in the wrong thread,
	 * possibly leading to all kinds of ugly issues.
	 */

	if (!Tcl_GetChannelThread(statePtr->channel)) {
	    CLEAR_BITS(statePtr->flags, TCP_ASYNC_PENDING);
	    Tcl_DeleteFileHandler(statePtr->fds.fd);
	}
    } else if (GOT_BITS(statePtr->flags, TCP_ASYNC_CONNECT)) {

	/*
	 * An async socket without an async event pending must just have been
	 * transferred from another thread. Reestablish the FileHandler here
	 * so the callback will run in the correct thread.
	 */

	Tcl_CreateFileHandler(statePtr->fds.fd,
			      TCL_WRITABLE | TCL_EXCEPTION, TcpAsyncCallback,
			      statePtr);
	SET_BITS(statePtr->flags, TCP_ASYNC_PENDING);

	/* Cache the current request until the connection has succeeded */
	statePtr->filehandlers = mask;
    } else if (mask) {

	/*
	 * Whether it is a bug or feature or otherwise, it is a fact of life
	 * that on at least some Linux kernels select() fails to report that a
	 * socket file descriptor is writable when the other end of the socket
	 * is closed.  This is in contrast to the guarantees Tcl makes that