From e021d7de474ab4755e8081e3009c328fd7d07c09 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Tue, 24 Sep 2013 08:28:43 +0000 Subject: [PATCH] context cleanup and subscribe, but still heavily broken --- go/door_client_zmq/main.go | 3 ++- go/door_client_zmq/zeromq.go | 9 ++++++--- go/door_daemon_zmq/main.go | 5 ++++- go/door_daemon_zmq/zeromq.go | 5 +++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/go/door_client_zmq/main.go b/go/door_client_zmq/main.go index 193c643..f63a0ee 100644 --- a/go/door_client_zmq/main.go +++ b/go/door_client_zmq/main.go @@ -55,9 +55,10 @@ func ByteArrayToString(bb [][]byte) string { } func main() { - cmd_chans, sub_chans := ZmqsInit(cmd_port_, sub_port_) + zmqctx, cmd_chans, sub_chans := ZmqsInit(cmd_port_, sub_port_) defer cmd_chans.Close() defer sub_chans.Close() + defer zmqctx.Close() var listen bool var ignore_next bool diff --git a/go/door_client_zmq/zeromq.go b/go/door_client_zmq/zeromq.go index 485e3f2..c91b7bd 100644 --- a/go/door_client_zmq/zeromq.go +++ b/go/door_client_zmq/zeromq.go @@ -9,9 +9,10 @@ import ( // ---------- ZeroMQ Code ------------- -func ZmqsInit(cmd_port, sub_port string) (cmd_chans, sub_chans *zmq.Channels) { - - ctx, err := zmq.NewContext() +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 { panic(err) } @@ -37,6 +38,8 @@ func ZmqsInit(cmd_port, sub_port string) (cmd_chans, sub_chans *zmq.Channels) { panic(err) } + sub_sock.Subscribe(subfilter) + if err = sub_sock.Connect(sub_port); err != nil { panic(err) } diff --git a/go/door_daemon_zmq/main.go b/go/door_daemon_zmq/main.go index 0ff877c..52e8197 100644 --- a/go/door_daemon_zmq/main.go +++ b/go/door_daemon_zmq/main.go @@ -44,7 +44,10 @@ func main() { os.Exit(1); } - cmd_chans, pub_chans := ZmqsInit(cmd_port_, pub_port_) + zmqctx, cmd_chans, pub_chans := ZmqsInit(cmd_port_, pub_port_) + defer cmd_chans.Close() + defer pub_chans.Close() + defer zmqctx.Close() serial_wr, err := OpenAndHandleSerial(args[0], pub_chans.Out()) defer close(serial_wr) diff --git a/go/door_daemon_zmq/zeromq.go b/go/door_daemon_zmq/zeromq.go index 8f20ec4..a4d8d68 100644 --- a/go/door_daemon_zmq/zeromq.go +++ b/go/door_daemon_zmq/zeromq.go @@ -9,9 +9,10 @@ import ( // ---------- ZeroMQ Code ------------- -func ZmqsInit(cmd_port, pub_port string) (cmd_chans, pub_chans *zmq.Channels) { +func ZmqsInit(cmd_port, pub_port string) (ctx *zmq.Context, cmd_chans, pub_chans *zmq.Channels) { - ctx, err := zmq.NewContext() + var err error + ctx, err = zmq.NewContext() if err != nil { panic(err) } -- 1.7.10.4