diff options
author | Steve Bennett <steveb@workware.net.au> | 2022-08-04 11:13:39 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2022-08-20 15:27:19 +1000 |
commit | 6e1d4cc163dc37f0ea5cdae8b3e2b9e4b0a73254 (patch) | |
tree | 9596172bde8edbcf87bcdb1d9012fa6d0a948167 /jim_tcl.txt | |
parent | 5af9d6a919b83e28a37ade2db8090a375a93ba53 (diff) | |
download | jimtcl-6e1d4cc163dc37f0ea5cdae8b3e2b9e4b0a73254.zip jimtcl-6e1d4cc163dc37f0ea5cdae8b3e2b9e4b0a73254.tar.gz jimtcl-6e1d4cc163dc37f0ea5cdae8b3e2b9e4b0a73254.tar.bz2 |
socket: add support for -async
Very similar to Tcl except that read/write can't be done until
writable indicates the socket is connected.
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Documentation fixes -
Co-authored-by: Adrian Ho <the.gromgit@gmail.com>
Diffstat (limited to 'jim_tcl.txt')
-rw-r--r-- | jim_tcl.txt | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/jim_tcl.txt b/jim_tcl.txt index f1ab2cd..2738d0b 100644 --- a/jim_tcl.txt +++ b/jim_tcl.txt @@ -5135,18 +5135,18 @@ Various socket types may be created. +*socket unix.dgram.server* 'path'+:: A unix domain socket datagram server server listening on 'path' -+*socket ?-ipv6? stream* 'addr:port'+:: ++*socket ?-async? ?-ipv6? stream* 'addr:port'+:: A TCP socket client. (See the forms for +'addr'+ below) -+*socket ?-ipv6? stream.server* '?addr:?port'+:: ++*socket ?-async? ?-ipv6? stream.server* '?addr:?port'+:: A TCP socket server (+'addr'+ defaults to +0.0.0.0+ for IPv4 or +[::]+ for IPv6). -+*socket ?-ipv6? dgram* ?'addr:port'?+:: ++*socket ?-async? ?-ipv6? dgram* ?'addr:port'?+:: A UDP socket client. If the address is not specified, the client socket will be unbound and 'sendto' must be used to indicated the destination. -+*socket ?-ipv6? dgram.server* 'addr:port'+:: ++*socket ?-async? ?-ipv6? dgram.server* 'addr:port'+:: A UDP socket server. +*socket pipe*+:: @@ -5209,6 +5209,38 @@ The path for Unix domain sockets is automatically removed when the socket is closed. Use `close -nodelete` in the rare case where this behaviour should be avoided (e.g. after `os.fork`). +If '+-async+' is specified, the socket is opened in non-blocking (ndelay) mode +and 'connect' is non-blocking (applies to 'stream'). In this case, a 'writable' handler +should be used that will fire when the connect succeeds or fails, and calling 'peername' on the handle +will succeed if connected or fail if connect failed. Typical usage is as follows: + +---- + set s [socket -async stream host:port] + + $s writable { + # Remove writable either way + $s writable {} + try { + $s peername + } on error msg { + # Connect failed + incr done + return + } + + $s readable { + set buf [$s read] + if {[$s eof]} { + # Closed connection + incr done + } + ... + } + } + + vwait done +---- + syslog ~~~~~~ +*syslog* '?options? ?priority? message'+ |