summaryrefslogtreecommitdiffstats
path: root/win/tclWinSock.c
diff options
context:
space:
mode:
authormax <max@tclers.tk>2014-03-05 14:40:27 (GMT)
committermax <max@tclers.tk>2014-03-05 14:40:27 (GMT)
commitf320ea76a37f8837d998a6400000d59b72d1e376 (patch)
tree9d63aeec6c3e72015ff115659c6aff4533f2f991 /win/tclWinSock.c
parentbf23be680c6a9233bd70707a05513b31b047d158 (diff)
downloadtcl-f320ea76a37f8837d998a6400000d59b72d1e376.zip
tcl-f320ea76a37f8837d998a6400000d59b72d1e376.tar.gz
tcl-f320ea76a37f8837d998a6400000d59b72d1e376.tar.bz2
Refactor the error handling logic around connect()
Diffstat (limited to 'win/tclWinSock.c')
-rw-r--r--win/tclWinSock.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index f06aad1..d7b1b5b 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -1176,6 +1176,7 @@ CreateClientSocket(
int async = infoPtr->flags & SOCKET_ASYNC_CONNECT;
int async_callback = infoPtr->sockets->fd != INVALID_SOCKET;
ThreadSpecificData *tsdPtr;
+ DWORD error;
DEBUG(async ? "async" : "sync");
@@ -1258,7 +1259,7 @@ CreateClientSocket(
*/
if (async) {
ThreadSpecificData *tsdPtr = TclThreadDataKeyGet(&dataKey);
- infoPtr->selectEvents |= FD_CONNECT;
+ infoPtr->selectEvents |= FD_CONNECT | FD_READ | FD_WRITE;
ioctlsocket(infoPtr->sockets->fd, (long) FIONBIO, &flag);
SendMessage(tsdPtr->hwnd, SOCKET_SELECT, (WPARAM) SELECT,
@@ -1268,26 +1269,22 @@ CreateClientSocket(
/*
* Attempt to connect to the remote socket.
*/
-
- if (connect(infoPtr->sockets->fd, infoPtr->addr->ai_addr,
- infoPtr->addr->ai_addrlen) == SOCKET_ERROR) {
- DWORD error = (DWORD) WSAGetLastError();
- TclWinConvertError(error);
- DEBUG("connect()");
+
+ DEBUG("connect()");
+ connect(infoPtr->sockets->fd, infoPtr->addr->ai_addr,
+ infoPtr->addr->ai_addrlen);
+ error = WSAGetLastError();
+ TclWinConvertError(error);
#ifdef DEBUGGING
- // fprintf(stderr,"error = %lu\n", error);
+ // fprintf(stderr,"error = %lu\n", error);
#endif
- if (error == WSAEWOULDBLOCK) {
- DEBUG("WSAEWOULDBLOCK");
- return TCL_OK;
- reenter:
- Tcl_SetErrno(infoPtr->lastError);
- DEBUG("reenter");
- infoPtr->selectEvents &= ~(FD_CONNECT);
- }
- } else {
- DWORD error = (DWORD) WSAGetLastError();
- TclWinConvertError(error);
+ if (error == WSAEWOULDBLOCK) {
+ DEBUG("WSAEWOULDBLOCK");
+ return TCL_OK;
+ reenter:
+ Tcl_SetErrno(infoPtr->lastError);
+ DEBUG("reenter");
+ infoPtr->selectEvents &= ~(FD_CONNECT);
}
#ifdef DEBUGGING
fprintf(stderr, "lastError: %d\n", Tcl_GetErrno());
@@ -1311,7 +1308,7 @@ out:
/*
* Set up the select mask for read/write events.
*/
-
+ DEBUG("selectEvents = FD_READ | FD_WRITE | FD_CLOSE");
infoPtr->selectEvents = FD_READ | FD_WRITE | FD_CLOSE;
/*