Attachment "async-nonblo.patch" to
ticket [3401422fff]
added by
ferrieux
2011-09-02 01:40:21.
Index: unix/tclUnixSock.c
===================================================================
--- unix/tclUnixSock.c
+++ unix/tclUnixSock.c
@@ -66,10 +66,11 @@
struct addrinfo *myaddrlist; /* local address */
struct addrinfo *myaddr; /* iterator over myaddrlist */
int filehandlers; /* Caches FileHandlers that get set up while
* an async socket is not yet connected */
int status; /* Cache status of async socket */
+ int cachedBlocking; /* Cache blocking mode of async socket */
};
/*
* These bits may be ORed together into the "flags" field of a TcpState
* structure.
@@ -345,10 +346,14 @@
if (mode == TCL_MODE_BLOCKING) {
CLEAR_BITS(statePtr->flags, TCP_ASYNC_SOCKET);
} else {
SET_BITS(statePtr->flags, TCP_ASYNC_SOCKET);
+ }
+ if (statePtr->flags & TCP_ASYNC_CONNECT) {
+ statePtr->cachedBlocking = mode;
+ return 0;
}
if (TclUnixSetBlockingMode(statePtr->fds.fd, mode) < 0) {
return errno;
}
return 0;
@@ -1036,11 +1041,11 @@
/*
* An asynchonous connection has finally succeeded or failed.
*/
CLEAR_BITS(state->flags, TCP_ASYNC_CONNECT);
TcpWatchProc(state, state->filehandlers);
- TclUnixSetBlockingMode(state->fds.fd, TCL_MODE_BLOCKING);
+ TclUnixSetBlockingMode(state->fds.fd, state->cachedBlocking);
/*
* We need to forward the writable event that brought us here, bcasue
* upon reading of getsockopt(SO_ERROR), at least some OSes clear the
* writable state from the socket, and so a subsequent select() on
@@ -1120,10 +1125,11 @@
* Allocate a new TcpState for this socket.
*/
state = ckalloc(sizeof(TcpState));
memset(state, 0, sizeof(TcpState));
state->flags = async ? TCP_ASYNC_CONNECT : 0;
+ state->cachedBlocking = TCL_MODE_BLOCKING;
state->addrlist = addrlist;
state->myaddrlist = myaddrlist;
state->fds.fd = -1;
/*