For a reason I do not understand (related to fconfigure/fileevent?),
the applications run1, run2 and run3 work serially after one another.
If I put "&" after sleep command, the main function will close BEFORE
all applications conclude.
The short code is attached.
Please, would some guru enlighten me ?
thanks,
ron
#!/bin/sh
# \
exec tclsh "$0" "$@"
proc getIP {} {
set server [socket -server "#" 0]
set pn "[lindex [fconfigure $server -sockname] 2]"
set client [socket [info hostname] $pn]
set ip [lindex [fconfigure $client -sockname] 0]
close $client
close $server
return $ip
}
proc run1 { portN ipAdd } {
puts " run1"
set k [socket $ipAdd $portN ]
fconfigure $k -buffering line
set t1 [exec sleep 10 ]
exec ls
puts $k tryrun2
close $k
}
proc run2 { portN ipAdd } {
puts " run2"
set m [socket $ipAdd $portN]
fconfigure $m -blocking 0 -buffering line
set t2 [exec sleep 5 ]
puts $m tryrun2
close $m
}
proc run3 { portN ipAdd } {
puts " run3"
set n [socket $ipAdd $portN]
fconfigure $n -buffering line
set t3 [exec sleep 10 ]
exec ls -la
puts $n tryrun3
close $n
}
proc accept {s a port} {
fileevent $s readable [list echo $s]
fconfigure $s -translation lf -buffering line -blocking 1
puts "connection from $a $port with s = $s"
}
proc echo {s} {
global x
set l [gets $s]
if {[eof $s]} {
puts " will close $s"
close $s
set x done
} else {
puts $s "Echoed: $l"
puts "Echoed to stdout: $l"
}
}
set ip_info [getIP]
set s [socket -server accept 0]
set try "[lindex [fconfigure $s -sockname] 2]"
set a [eval [exec [concat [ run1 $try $ip_info ] >& a.log ]&]]
set b [eval [exec [concat [ run2 $try $ip_info ] >& b.log & ]&]]
set c [eval [exec [concat [ run3 $try $ip_info ] >& c.log ] <@ $s >&@
$s ]]
vwait x;
vwait x;
vwait x;
puts "done ... will close server $s"
close $s
Ronald wrote:
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester | "The man who fights for his ideals is
|
| Gerald...@cox.net | the man who is alive." -- Cervantes
|
+--------------------------------+---------------------------------------+
Cameron Laird <Cam...@Lairds.com>
Business: http://www.Phaseit.net
Personal: http://starbase.neosoft.com/~claird/home.html