# $master socket
# $permissions [list allow|super|deny $ipaddrhex $maskhex ...]
# $realtime pipes
-# $realtime_retry [list $serialchan $timeoutid $awaitedpongmsg|{} $buf]
+# $realtime_retry [list $timeoutid $awaitedpongmsg|{} $buf]
# $replay("$pri $key") $rhs $pri is \d\d; causes replay of "$key $rhs"
# $detect0($seg) unset -> 1 or irrelevant; [after ...]
# $conns($conn) 1
global realtime_retry
if {![info exists realtime_retry]} return
if {![llength $realtime_retry]} return
- manyset $realtime_retry serchan timeoutid
- catch { close $serchan }
+ manyset $realtime_retry timeoutid
+ fileevent $serchan readable {}
after cancel $timeoutid
set realtime_retry {}
}
}
proc realtime-retry-realtime-failed {} {
- global realtime_retry dev_railway
+ global realtime_retry dev_railway serchan
if {![info exists realtime_retry]} return
if {[llength $realtime_retry]} { error "huh? $realtime_retry" }
- set serchan [open $dev_railway {RDWR NOCTTY NONBLOCK}]
- fconfigure $serchan -translation binary -buffering none -blocking 0
fileevent $serchan readable realtime-retry-serchan-readable
set after [after 500 realtime-retry-send-ping]
- set realtime_retry [list $serchan $after {} {}]
+ set realtime_retry [list $after {} {}]
}
proc realtime-retry-send-ping {} {
- global realtime_retry urandom
- manyset $realtime_retry serchan after pong buf
+ global realtime_retry urandom serchan
+ manyset $realtime_retry after pong buf
set x [read $urandom 2]
binary scan $x H* x
if {[string length $x] != 4} { error "urandom short read `$x'" }
#puts "<! picioh out await-off $pong (await $pong)"
puts -nonewline $serchan [binary format H* $ping]
set after [after 700 realtime-retry-now-off]
- set realtime_retry [list $serchan $after $pong {}]
+ set realtime_retry [list $after $pong {}]
}
proc realtime-retry-serchan-readable {} {
- global realtime_retry
- manyset $realtime_retry serchan after pong buf
+ global realtime_retry serchan
+ manyset $realtime_retry after pong buf
set x [read $serchan]
binary scan $x H* x
#puts "<! picioh in await-off $x"
if {![string compare $pong $msg]} {
after cancel $after
set after [after 200 realtime-retry-send-ping]
- set realtime_retry [list $serchan $after {} {}]
+ set realtime_retry [list $after {} {}]
return
}
}
- set realtime_retry [list $serchan $after $pong $buf]
+ set realtime_retry [list $after $pong $buf]
}
proc realtime-retry-now-off {} {
}
proc startup {} {
- global queueing executing testmode realtime port urandom
+ global queueing executing testmode realtime port urandom serchan
catch { close $master }; catch { unset master }
setting testmode 0 {[01]}
uplevel #0 source multiplex-config
set queueing {}
set executing 0
+
set urandom [open /dev/urandom r]
fconfigure $urandom -buffering none -translation binary
+
+ set serchan [open $dev_railway {RDWR NOCTTY NONBLOCK}]
+ fconfigure $serchan -translation binary -buffering none -blocking 0
+
realtime-notrunning
+
if {!$testmode} {
start_commandloop
after idle realtime-retry-check