diff options
| author | Omar Rizwan <omar@omar.website> | 2023-02-14 07:28:27 +0000 |
|---|---|---|
| committer | Omar Rizwan <omar@omar.website> | 2023-02-14 07:28:27 +0000 |
| commit | 3ac7beb4bf551f92aca0358f9bb5fa46876f19c7 (patch) | |
| tree | eaf473b476381702f024260a6da58742d5471375 /lib | |
| parent | Refactor peering. Refactor process. (diff) | |
| download | folk-3ac7beb4bf551f92aca0358f9bb5fa46876f19c7.tar.gz folk-3ac7beb4bf551f92aca0358f9bb5fa46876f19c7.zip | |
More cleanup/refactoring of peering.
Start trying to test IPC statements.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/peer.tcl | 10 | ||||
| -rw-r--r-- | lib/process.tcl | 10 |
2 files changed, 11 insertions, 9 deletions
diff --git a/lib/peer.tcl b/lib/peer.tcl index ca9c473a..e46017a0 100644 --- a/lib/peer.tcl +++ b/lib/peer.tcl @@ -1,8 +1,11 @@ +lappend auto_path "./vendor" +package require websocket + proc ::peer {node} { namespace eval Peers::$node { proc setupSock {} { variable node - puts "sharer: Trying to connect to: ws://$node:4273/ws" + puts "peer: Trying to connect to: ws://$node:4273/ws" variable sock [::websocket::open "ws://$node:4273/ws" [namespace code handleWs]] } proc handleWs {sock type msg} { @@ -26,10 +29,7 @@ proc ::peer {node} { ::websocket::send $sock text $msg } - proc init {n} { - variable node $n - setupSock - } + proc init {n} { variable node $n; setupSock } init } $node } diff --git a/lib/process.tcl b/lib/process.tcl index 1bca66da..5208384b 100644 --- a/lib/process.tcl +++ b/lib/process.tcl @@ -4,15 +4,16 @@ set ::processPrelude { try $body after $ms [list after idle [namespace code [info level 0]]] } - # TODO: do a socket connection to localhost - + + source "lib/peer.tcl" + peer "localhost" } proc On-process {name body} { namespace eval ::Processes::$name {} set ::Processes::${name}::name $name set ::Processes::${name}::body $body - set ::Processes::${name}::this [uplevel {set this}] + set ::Processes::${name}::this [uplevel {expr {[info exists this] ? $this : "<unknown>"}}] namespace eval ::Processes::$name { variable tclfd [file tempfile tclfile tclfile.tcl] puts $tclfd [join [list $::processPrelude $body] "\n"]; close $tclfd @@ -28,6 +29,7 @@ proc On-process {name body} { variable log if {[gets $stdio line] >= 0} { lappend log $line + puts "$name: $line" Retract process $name has standard output log /l/ Assert process $name has standard output log $log Step @@ -36,7 +38,7 @@ proc On-process {name body} { fconfigure $stdio -blocking 0 -buffering line fileevent $stdio readable [namespace code handleReadable] - if {[info exists this]} { + if {$this ne "<unknown>"} { Assert $this is running process $name } |
