1 // (c) Bernhard Tittelbach, 2013
6 zmq "github.com/vaughan0/go-zmq"
10 // ---------- ZeroMQ Code -------------
12 func ZmqsInit(cmd_port, pub_port string) (ctx *zmq.Context, cmd_chans, pub_chans *zmq.Channels) {
15 ctx, err = zmq.NewContext()
19 //close only on later panic, otherwise leave open:
20 defer func(){ if r:= recover(); r != nil { ctx.Close(); panic(r) } }()
22 if len(cmd_port) > 0 {
23 cmd_sock, err := ctx.Socket(zmq.Rep)
27 defer func() { if r:= recover(); r != nil { cmd_sock.Close(); panic(r) } }()
29 cmd_sock.SetRecvTimeout(2 * time.Second)
30 cmd_sock.SetSendTimeout(2 * time.Second)
32 if err = cmd_sock.Bind(cmd_port); err != nil {
36 cmd_chans = cmd_sock.ChannelsBuffer(10)
37 go zmqsHandleError(cmd_chans)
42 if len(pub_port) > 0 {
43 pub_sock, err := ctx.Socket(zmq.Pub)
47 defer func() { if r:= recover(); r != nil { pub_sock.Close(); panic(r) } }()
49 if err = pub_sock.Bind(pub_port); err != nil {
53 pub_chans = pub_sock.ChannelsBuffer(10)
54 go zmqsHandleError(pub_chans)
62 func zmqsHandleError(chans *zmq.Channels) {
63 for error := range(chans.Errors()) {