diff options
author | max <max@tclers.tk> | 2011-06-16 15:21:10 (GMT) |
---|---|---|
committer | max <max@tclers.tk> | 2011-06-16 15:21:10 (GMT) |
commit | a2c0c5611d68ee996777ad68e480daae28488ad9 (patch) | |
tree | 4b2e1bc43ca9510d8c2daa9387ed66843996aaa4 | |
parent | f5123e0b70f74ddc3f0521870aa1c318aff0aef6 (diff) | |
download | tcl-a2c0c5611d68ee996777ad68e480daae28488ad9.zip tcl-a2c0c5611d68ee996777ad68e480daae28488ad9.tar.gz tcl-a2c0c5611d68ee996777ad68e480daae28488ad9.tar.bz2 |
* doc/socket.n: Document the fact that the event loop is now needed for [socket -async]
* unix/tclUnixSock.c: Set up the file handler for async sockets to fire on exceptions in addition to writable state.
* tests/socket.test: Improve error reporting when socket-14.2 times out.
-rw-r--r-- | doc/socket.n | 23 | ||||
-rw-r--r-- | tests/socket.test | 3 | ||||
-rw-r--r-- | unix/tclUnixSock.c | 3 |
3 files changed, 22 insertions, 7 deletions
diff --git a/doc/socket.n b/doc/socket.n index 0e427ed..0cb0595 100644 --- a/doc/socket.n +++ b/doc/socket.n @@ -71,12 +71,14 @@ port number will be chosen at random by the system software. This option will cause the client socket to be connected asynchronously. This means that the socket will be created immediately but may not yet be connected to the server, when the call to -\fBsocket\fR returns. When a \fBgets\fR or \fBflush\fR is done on the -socket before the connection attempt succeeds or fails, if the socket -is in blocking mode, the operation will wait until the connection is -completed or fails. If the socket is in nonblocking mode and a -\fBgets\fR or \fBflush\fR is done on the socket before the connection -attempt succeeds or fails, the operation returns immediately and +\fBsocket\fR returns. + +When a \fBgets\fR or \fBflush\fR is done on the socket before the +connection attempt succeeds or fails, if the socket is in blocking +mode, the operation will wait until the connection is completed or +fails. If the socket is in nonblocking mode and a \fBgets\fR or +\fBflush\fR is done on the socket before the connection attempt +succeeds or fails, the operation returns immediately and \fBfblocked\fR on the socket returns 1. Synchronous client sockets may be switched (after they have connected) to operating in asynchronous mode using: @@ -87,6 +89,15 @@ mode using: .CE .PP See the \fBchan\fR \fBconfigure\fR command for more details. + +The Tcl event loop should be running while an asynchronous connection +is in progress, because it may have to do several connection attempts +in the background. Runnig the event loop also allows you to set up a +writable channel event on the socket to get notified when the +asyncronous connection has succeeded or failed. See the \fBvwait\fR +and the \fBchan\fR comands for more details on the event loop and +channel events. + .RE .SH "SERVER SOCKETS" .PP diff --git a/tests/socket.test b/tests/socket.test index 39dc8de..85d4d6f 100644 --- a/tests/socket.test +++ b/tests/socket.test @@ -1772,6 +1772,9 @@ test socket-14.2 {[socket -async] fileevent connection refused} \ fileevent $client writable {set x [fconfigure $client -error]} set after [after 1000 {set x timeout}] vwait x + if {$x eq "timeout"} { + append x ": [fconfigure $client -error]" + } set x } -cleanup { after cancel $after diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index a883e8c..5ace251 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.c @@ -971,7 +971,8 @@ CreateClientSocket( status = connect(state->fds.fd, state->addr->ai_addr, state->addr->ai_addrlen); if (status < 0 && errno == EINPROGRESS) { - Tcl_CreateFileHandler(state->fds.fd, TCL_WRITABLE, + Tcl_CreateFileHandler(state->fds.fd, + TCL_WRITABLE | TCL_EXCEPTION, TcpAsyncCallback, state); return TCL_OK; |