chiark / gitweb /
keep serchan open to defeat stupid kernel bug (EIO when opening a tty someone else...
authorian <ian>
Mon, 14 Jul 2008 21:16:54 +0000 (21:16 +0000)
committerian <ian>
Mon, 14 Jul 2008 21:16:54 +0000 (21:16 +0000)
hostside/multiplex

index 25b48cd4084b5934044ae6f62ef49623a62903be..4284bc7c6ccbf8e4fa4c589c19382a88599bfd67 100755 (executable)
@@ -12,7 +12,7 @@
 #    $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
@@ -276,8 +276,8 @@ proc realtime-retry-reset {} {
     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 {}
 }
@@ -291,19 +291,17 @@ proc realtime-retry-check {} {
 }
 
 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'" }
@@ -313,12 +311,12 @@ proc realtime-retry-send-ping {} {
     #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"
@@ -332,11 +330,11 @@ proc realtime-retry-serchan-readable {} {
        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 {} {
@@ -814,7 +812,7 @@ proc binding {addr blist} {
 }
 
 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]}
@@ -823,9 +821,15 @@ proc startup {} {
     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