From 9a37d1b81db952b8026ce0eeefeff871ea0075a7 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Tue, 24 Sep 2013 19:41:51 +0000 Subject: [PATCH] cleanup, but sub still does not work --- go/door_client_zmq/main.go | 2 -- go/door_client_zmq/zeromq.go | 11 +++++++---- go/door_daemon_zmq/main.go | 6 ------ go/door_daemon_zmq/zeromq.go | 4 ++-- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/go/door_client_zmq/main.go b/go/door_client_zmq/main.go index f63a0ee..a49fb88 100644 --- a/go/door_client_zmq/main.go +++ b/go/door_client_zmq/main.go @@ -80,9 +80,7 @@ func main() { default: ignore_next = true cmd_chans.Out() <- input - log.Print("input sent") reply := <- cmd_chans.In() - log.Print("reply received") fmt.Println(ByteArrayToString(reply)) } } else { diff --git a/go/door_client_zmq/zeromq.go b/go/door_client_zmq/zeromq.go index 8536c66..abf17b2 100644 --- a/go/door_client_zmq/zeromq.go +++ b/go/door_client_zmq/zeromq.go @@ -10,7 +10,6 @@ import ( // ---------- ZeroMQ Code ------------- func ZmqsInit(cmd_port, sub_port string) (ctx *zmq.Context, cmd_chans, sub_chans *zmq.Channels) { - var subfilter []byte var err error ctx, err = zmq.NewContext() if err != nil { @@ -32,7 +31,7 @@ func ZmqsInit(cmd_port, sub_port string) (ctx *zmq.Context, cmd_chans, sub_chan if err = cmd_sock.Connect(cmd_port); err != nil { panic(err) } - + cmd_chans = cmd_sock.ChannelsBuffer(10) go zmqsHandleError(cmd_chans) } else { @@ -46,7 +45,11 @@ func ZmqsInit(cmd_port, sub_port string) (ctx *zmq.Context, cmd_chans, sub_chan } defer func() { if r:= recover(); r != nil { sub_sock.Close(); panic(r) } }() - sub_sock.Subscribe(subfilter) + sub_sock.Subscribe([]byte("close")) + sub_sock.Subscribe([]byte("toggle")) + sub_sock.Subscribe([]byte("Info")) + sub_sock.Subscribe([]byte("State")) + sub_sock.Subscribe([]byte("open")) if err = sub_sock.Connect(sub_port); err != nil { panic(err) @@ -64,6 +67,6 @@ func ZmqsInit(cmd_port, sub_port string) (ctx *zmq.Context, cmd_chans, sub_chan func zmqsHandleError(chans *zmq.Channels) { for error := range(chans.Errors()) { chans.Close() - panic(error) + panic(error) } } diff --git a/go/door_daemon_zmq/main.go b/go/door_daemon_zmq/main.go index 8d376be..facedac 100644 --- a/go/door_daemon_zmq/main.go +++ b/go/door_daemon_zmq/main.go @@ -7,7 +7,6 @@ import ( "os" "flag" "time" - //~ "log" ) //~ func StringArrayToByteArray(ss []string) [][]byte { @@ -81,18 +80,13 @@ func main() { } case incoming_request, ic_notclosed := <- cmd_chans.In(): if ! ic_notclosed {os.Exit(2)} - //~ log.Print(incoming_request) if err := HandleCommand(incoming_request, serial_wr, serial_rd); err != nil { - //~ log.Print(err) out_msg := [][]byte{[]byte("ERROR"), []byte(err.Error())} cmd_chans.Out() <- out_msg - //~ log.Print("sent error") } else { - //~ log.Print(reply) pub_chans.Out() <- incoming_request next_incoming_serial_is_client_reply = true go func(){time.Sleep(3*time.Second); timeout_chan <- true;}() - //~ log.Print("sent reply") } } } diff --git a/go/door_daemon_zmq/zeromq.go b/go/door_daemon_zmq/zeromq.go index 805368e..6db3ea8 100644 --- a/go/door_daemon_zmq/zeromq.go +++ b/go/door_daemon_zmq/zeromq.go @@ -32,7 +32,7 @@ func ZmqsInit(cmd_port, pub_port string) (ctx *zmq.Context, cmd_chans, pub_chan if err = cmd_sock.Bind(cmd_port); err != nil { panic(err) } - + cmd_chans = cmd_sock.ChannelsBuffer(10) go zmqsHandleError(cmd_chans) } else { @@ -62,6 +62,6 @@ func ZmqsInit(cmd_port, pub_port string) (ctx *zmq.Context, cmd_chans, pub_chan func zmqsHandleError(chans *zmq.Channels) { for error := range(chans.Errors()) { chans.Close() - panic(error) + panic(error) } } \ No newline at end of file -- 1.7.10.4