diff options
author | max <max@tclers.tk> | 2014-03-10 18:11:08 (GMT) |
---|---|---|
committer | max <max@tclers.tk> | 2014-03-10 18:11:08 (GMT) |
commit | 4964ea0ff919aca3e872155d323cd72868cb93f3 (patch) | |
tree | fc99721f9ac6869e4f7cad85a7209198940d905d | |
parent | 138267abe275e454e892fe55ad5f3e16fd032278 (diff) | |
download | tcl-4964ea0ff919aca3e872155d323cd72868cb93f3.zip tcl-4964ea0ff919aca3e872155d323cd72868cb93f3.tar.gz tcl-4964ea0ff919aca3e872155d323cd72868cb93f3.tar.bz2 |
WaitForConnect may only call back to CreateClientSocket when the socket is writable or something. When it does so for a pending socket, it is falsely assumed to have succeeded and a subsequent read/write operation will fail.
-rw-r--r-- | tests/socket.test | 4 | ||||
-rw-r--r-- | unix/tclUnixSock.c | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/tests/socket.test b/tests/socket.test index bfe6990..a21bb8d 100644 --- a/tests/socket.test +++ b/tests/socket.test @@ -2006,7 +2006,7 @@ test socket-14.8.0 {pending [socket -async] and nonblocking [gets], server is IP set sock [socket -async localhost $port] fconfigure $sock -blocking 0 for {set i 0} {$i < 50} {incr i } { - if {[set x [gets $sock]] ne ""} break + if {[catch {gets $sock} x] || $x ne "" || ![fblocked $sock]} break after 200 } set x @@ -2032,7 +2032,7 @@ test socket-14.8.1 {pending [socket -async] and nonblocking [gets], server is IP set sock [socket -async localhost $port] fconfigure $sock -blocking 0 for {set i 0} {$i < 50} {incr i } { - if {[set x [gets $sock]] ne ""} break + if {[catch {gets $sock} x] || $x ne "" || ![fblocked $sock]} break after 200 } set x diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index 41d729e..6e84ed5 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.c @@ -417,7 +417,9 @@ WaitForConnect( errno = 0; state = TclUnixWaitForFile(statePtr->fds.fd, TCL_WRITABLE | TCL_EXCEPTION, timeOut); - CreateClientSocket(NULL, statePtr); + if (state != 0) { + CreateClientSocket(NULL, statePtr); + } if (statePtr->flags & TCP_ASYNC_CONNECT) { /* We are still in progress, so ignore the result of the last * attempt */ |