| ︙ | | | ︙ | |
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# Copyright (c) 1991-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: io.test,v 1.20 2001/07/31 19:12:07 vincentdarley Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
namespace import -force ::tcltest::*
}
tcltest::testConstraint testchannel [string equal testchannel [info commands testchannel]]
|
|
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# Copyright (c) 1991-1994 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: io.test,v 1.21 2001/09/11 17:30:44 andreas_kupries Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
namespace import -force ::tcltest::*
}
tcltest::testConstraint testchannel [string equal testchannel [info commands testchannel]]
|
| ︙ | | | ︙ | |
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
|
if {[eof $s]} {
close $s
set x done
} elseif {([string length $l] > 0) || ![fblocked $s]} {
incr c
}
}
set ss [socket -server accept 2828]
set cs [socket [info hostname] 2828]
vwait x
fconfigure $cs -blocking off
writelots $cs $l
close $cs
close $ss
vwait x
set c
} 2000
test io-29.35 {Tcl_Close vs fileevent vs multiple interpreters} {socket tempNotMac} {
# On Mac, this test screws up sockets such that subsequent tests using port 2828
# either cause errors or panic().
catch {interp delete x}
catch {interp delete y}
interp create x
interp create y
set s [socket -server accept 2828]
proc accept {s a p} {
puts $s hello
close $s
}
set c [socket [info hostname] 2828]
interp share {} $c x
interp share {} $c y
close $c
x eval {
proc readit {s} {
gets $s
if {[eof $s]} {
|
|
|
|
|
|
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
|
if {[eof $s]} {
close $s
set x done
} elseif {([string length $l] > 0) || ![fblocked $s]} {
incr c
}
}
set ss [socket -server accept 0]
set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]
vwait x
fconfigure $cs -blocking off
writelots $cs $l
close $cs
close $ss
vwait x
set c
} 2000
test io-29.35 {Tcl_Close vs fileevent vs multiple interpreters} {socket tempNotMac} {
# On Mac, this test screws up sockets such that subsequent tests using port 2828
# either cause errors or panic().
catch {interp delete x}
catch {interp delete y}
interp create x
interp create y
set s [socket -server accept 0]
proc accept {s a p} {
puts $s hello
close $s
}
set c [socket [info hostname] [lindex [fconfigure $s -sockname] 2]]
interp share {} $c x
interp share {} $c y
close $c
x eval {
proc readit {s} {
gets $s
if {[eof $s]} {
|
| ︙ | | | ︙ | |
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
|
proc accept {s a p} {
global x wait
fconfigure $s -blocking off
puts $s "sock[incr x]"
close $s
set wait done
}
set ss [socket -server accept 2831]
set wait ""
set cs [socket [info hostname] 2831]
vwait wait
lappend result [gets $cs]
close $cs
set wait ""
set cs [socket [info hostname] 2831]
vwait wait
lappend result [gets $cs]
close $cs
set wait ""
set cs [socket [info hostname] 2831]
vwait wait
lappend result [gets $cs]
close $cs
set wait ""
set cs [socket [info hostname] 2831]
vwait wait
lappend result [gets $cs]
close $cs
close $ss
set result
} {sock1 sock2 sock3 sock4}
|
|
|
>
>
>
>
>
>
|
|
<
<
<
<
<
<
|
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
|
proc accept {s a p} {
global x wait
fconfigure $s -blocking off
puts $s "sock[incr x]"
close $s
set wait done
}
set ss [socket -server accept 0]
set wait ""
set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]
vwait wait
lappend result [gets $cs]
close $cs
set wait ""
set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]
vwait wait
lappend result [gets $cs]
close $cs
set wait ""
set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]
vwait wait
lappend result [gets $cs]
close $cs
set wait ""
set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]
vwait wait
lappend result [gets $cs]
close $cs
close $ss
set result
} {sock1 sock2 sock3 sock4}
|
| ︙ | | | ︙ | |
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
|
set fcopyTestDone 1
} else {
set fcopyTestDone 0
}
}
test io-53.5 {CopyData: error during fcopy} {socket} {
set listen [socket -server FcopyTestAccept 2828]
set in [open $thisScript] ;# 126 K
set out [socket 127.0.0.1 2828]
catch {unset fcopyTestDone}
close $listen ;# This means the socket open never really succeeds
fcopy $in $out -command FcopyTestDone
if ![info exists fcopyTestDone] {
vwait fcopyTestDone ;# The error occurs here in the b.g.
}
close $in
|
|
|
|
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
|
set fcopyTestDone 1
} else {
set fcopyTestDone 0
}
}
test io-53.5 {CopyData: error during fcopy} {socket} {
set listen [socket -server FcopyTestAccept 0]
set in [open $thisScript] ;# 126 K
set out [socket 127.0.0.1 [lindex [fconfigure $listen -sockname] 2]]
catch {unset fcopyTestDone}
close $listen ;# This means the socket open never really succeeds
fcopy $in $out -command FcopyTestDone
if ![info exists fcopyTestDone] {
vwait fcopyTestDone ;# The error occurs here in the b.g.
}
close $in
|
| ︙ | | | ︙ | |
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
|
lappend result $next
if {$next == 1} {
fileevent $s readable [list readit $s 2]
vwait x
}
incr x
}
set ss [socket -server accept 2828]
# We need to delay on some systems until the creation of the
# server socket completes.
set done 0
for {set i 0} {$i < 10} {incr i} {
if {![catch {set cs [socket [info hostname] 2828]}]} {
set done 1
break
}
after 100
}
if {$done == 0} {
close $ss
|
|
|
|
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
|
lappend result $next
if {$next == 1} {
fileevent $s readable [list readit $s 2]
vwait x
}
incr x
}
set ss [socket -server accept 0]
# We need to delay on some systems until the creation of the
# server socket completes.
set done 0
for {set i 0} {$i < 10} {incr i} {
if {![catch {set cs [socket [info hostname] [lindex [fconfigure $ss -sockname] 2]]}]} {
set done 1
break
}
after 100
}
if {$done == 0} {
close $ss
|
| ︙ | | | ︙ | |
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
|
close $ss
close $cs
list $result $x
} {{{line 1} 1 2} 2}
test io-54.2 {Testing for busy-wait in recursive channel events} {socket} {
set accept {}
set after {}
set s [socket -server accept 3939]
proc accept {s a p} {
global counter accept
set accept $s
set counter 0
fconfigure $s -blocking off -buffering line -translation lf
fileevent $s readable "doit $s"
|
|
|
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
|
close $ss
close $cs
list $result $x
} {{{line 1} 1 2} 2}
test io-54.2 {Testing for busy-wait in recursive channel events} {socket} {
set accept {}
set after {}
set s [socket -server accept 0]
proc accept {s a p} {
global counter accept
set accept $s
set counter 0
fconfigure $s -blocking off -buffering line -translation lf
fileevent $s readable "doit $s"
|
| ︙ | | | ︙ | |
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
|
incr counter
set l [gets $s]
close $s
set accept {}
}
proc producer {} {
global writer
set writer [socket 127.0.0.1 3939]
fconfigure $writer -buffering line
puts -nonewline $writer hello
flush $writer
}
proc newline {} {
global writer done
|
|
|
|
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
|
incr counter
set l [gets $s]
close $s
set accept {}
}
proc producer {} {
global writer s
set writer [socket 127.0.0.1 [lindex [fconfigure $s -sockname] 2]]
fconfigure $writer -buffering line
puts -nonewline $writer hello
flush $writer
}
proc newline {} {
global writer done
|
| ︙ | | | ︙ | |
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
|
lappend result $y
} {2 done}
test io-57.1 {buffered data and file events, gets} {
proc accept {sock args} {
set ::s2 $sock
}
set server [socket -server accept 4040]
set s [socket 127.0.0.1 4040]
vwait s2
update
fileevent $s2 readable {lappend result readable}
puts $s "12\n34567890"
flush $s
set result [gets $s2]
after 1000 {lappend result timer}
vwait result
lappend result [gets $s2]
vwait result
close $s
close $s2
close $server
set result
} {12 readable 34567890 timer}
test io-57.2 {buffered data and file events, read} {
proc accept {sock args} {
set ::s2 $sock
}
set server [socket -server accept 4041]
set s [socket 127.0.0.1 4041]
vwait s2
update
fileevent $s2 readable {lappend result readable}
puts -nonewline $s "1234567890"
flush $s
set result [read $s2 1]
after 1000 {lappend result timer}
|
|
|
|
|
|
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
|
lappend result $y
} {2 done}
test io-57.1 {buffered data and file events, gets} {
proc accept {sock args} {
set ::s2 $sock
}
set server [socket -server accept 0]
set s [socket 127.0.0.1 [lindex [fconfigure $server -sockname] 2]]
vwait s2
update
fileevent $s2 readable {lappend result readable}
puts $s "12\n34567890"
flush $s
set result [gets $s2]
after 1000 {lappend result timer}
vwait result
lappend result [gets $s2]
vwait result
close $s
close $s2
close $server
set result
} {12 readable 34567890 timer}
test io-57.2 {buffered data and file events, read} {
proc accept {sock args} {
set ::s2 $sock
}
set server [socket -server accept 0]
set s [socket 127.0.0.1 [lindex [fconfigure $server -sockname] 2]]
vwait s2
update
fileevent $s2 readable {lappend result readable}
puts -nonewline $s "1234567890"
flush $s
set result [read $s2 1]
after 1000 {lappend result timer}
|
| ︙ | | | ︙ | |