summaryrefslogtreecommitdiffstats
path: root/tests/socket.test
diff options
context:
space:
mode:
authormax <max@tclers.tk>2011-06-28 11:32:15 (GMT)
committermax <max@tclers.tk>2011-06-28 11:32:15 (GMT)
commit1543959a9b88e49df5b1f1ba37872eeae9eabb1e (patch)
tree4e1697dfded4c6d7238c3c13f317b9a9c8a91ccb /tests/socket.test
parentc6201577c310d21572008b287406f4a520847d2a (diff)
downloadtcl-1543959a9b88e49df5b1f1ba37872eeae9eabb1e.zip
tcl-1543959a9b88e49df5b1f1ba37872eeae9eabb1e.tar.gz
tcl-1543959a9b88e49df5b1f1ba37872eeae9eabb1e.tar.bz2
* unix/tclUnixSock.c (CreateClientSocket): Fix and simplify posting of the writable fileevent at the end of an asynchronous connection attempt. Improve comments for some of the trickery around [socket -async]. [Bug 3325339]
* tests/socket.test: Adjust tests to the async code changes. Add more tests for corner cases of async sockets.
Diffstat (limited to 'tests/socket.test')
-rw-r--r--tests/socket.test67
1 files changed, 60 insertions, 7 deletions
diff --git a/tests/socket.test b/tests/socket.test
index 7f5c5c2..363f141 100644
--- a/tests/socket.test
+++ b/tests/socket.test
@@ -1751,21 +1751,23 @@ test socket-14.1 {[socket -async] fileevent while still connecting} \
}
set server [socket -server accept -myaddr 127.0.0.1 0]
set port [lindex [fconfigure $server -sockname] 2]
+ set x ""
} -body {
set client [socket -async localhost $port]
fileevent $client writable {
- lappend x [expr {[fconfigure $client -error] eq ""}]
+ lappend x [fconfigure $client -error]
}
- set after [after 1000 {set x timeout}]
- vwait x
- vwait x
- set x
+ set after [after 1000 {lappend x timeout}]
+ while {[llength $x] < 2 && "timeout" ni $x} {
+ vwait x
+ }
+ lsort $x; # we only want to see both events, the order doesn't matter
} -cleanup {
after cancel $after
close $server
close $client
unset x
- } -result {ok 1}
+ } -result {{} ok}
test socket-14.2 {[socket -async] fileevent connection refused} \
-constraints [list socket supported_any] \
-body {
@@ -1782,7 +1784,58 @@ test socket-14.2 {[socket -async] fileevent connection refused} \
close $client
unset x
} -result "connection refused"
-
+test socket-14.3 {[socket -async] fileevent host unreachable} \
+ -constraints [list socket supported_any] \
+ -body {
+ # address from rfc5737
+ set client [socket -async 192.0.2.42 [randport]]
+ fileevent $client writable {set x [fconfigure $client -error]}
+ set after [after 5000 {set x timeout}]
+ vwait x
+ if {$x eq "timeout"} {
+ append x ": [fconfigure $client -error]"
+ }
+ set x
+ } -cleanup {
+ after cancel $after
+ close $client
+ unset x
+ } -result "host is unreachable"
+test socket-14.4 {[socket -async] and both, readdable and writable fileevents} \
+ -constraints [list socket supported_any] \
+ -setup {
+ proc accept {s a p} {
+ puts $s bye
+ close $s
+ }
+ set server [socket -server accept -myaddr 127.0.0.1 0]
+ set port [lindex [fconfigure $server -sockname] 2]
+ set x ""
+ } -body {
+ set client [socket -async localhost $port]
+ fileevent $client writable {
+ lappend x [fconfigure $client -error]
+ fileevent $client writable {}
+ }
+ fileevent $client readable {lappend x [gets $client]}
+ set after [after 1000 {lappend x timeout}]
+ while {[llength $x] < 2 && "timeout" ni $x} {
+ vwait x
+ }
+ lsort $x
+ } -cleanup {
+ after cancel $after
+ close $client
+ close $server
+ } -result {{} bye}
+test socket-14.5 {[socket -async] which fails before any connect() can be made} \
+ -constraints [list socket supported_any] \
+ -body {
+ # addresses from rfc5737
+ socket -async -myaddr 192.0.2.42 198.51.100.42 [randport]
+ } \
+ -returnCodes 1 \
+ -result {couldn't open socket: cannot assign requested address}
::tcltest::cleanupTests
flush stdout
return