From: Bernhard Tittelbach Date: Tue, 24 Sep 2013 19:41:47 +0000 (+0000) Subject: --bug --crash X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=83655ca2cf31b0e0af2196f87efbd0b25aa72f92;p=svn42.git --bug --crash --- diff --git a/go/door_client_zmq/zeromq.go b/go/door_client_zmq/zeromq.go index c91b7bd..8536c66 100644 --- a/go/door_client_zmq/zeromq.go +++ b/go/door_client_zmq/zeromq.go @@ -16,52 +16,54 @@ func ZmqsInit(cmd_port, sub_port string) (ctx *zmq.Context, cmd_chans, sub_chan if err != nil { panic(err) } - //close only on panic, otherwise leave open: + //close only on later panic, otherwise leave open: defer func(){ if r:= recover(); r != nil { ctx.Close(); panic(r) } }() - cmd_sock, err := ctx.Socket(zmq.Req) - if err != nil { - panic(err) - } - defer func() { if r:= recover(); r != nil { cmd_sock.Close(); panic(r) } }() + if len(cmd_port) > 0 { + cmd_sock, err := ctx.Socket(zmq.Req) + if err != nil { + panic(err) + } + defer func() { if r:= recover(); r != nil { cmd_sock.Close(); panic(r) } }() - cmd_sock.SetRecvTimeout(2 * time.Second) - cmd_sock.SetSendTimeout(2 * time.Second) + cmd_sock.SetRecvTimeout(2 * time.Second) + cmd_sock.SetSendTimeout(2 * time.Second) - sub_sock, err := ctx.Socket(zmq.Sub) - if err != nil { - panic(err) + if err = cmd_sock.Connect(cmd_port); err != nil { + panic(err) + } + + cmd_chans = cmd_sock.ChannelsBuffer(10) + go zmqsHandleError(cmd_chans) + } else { + cmd_chans = nil } - defer func() { if r:= recover(); r != nil { sub_sock.Close(); panic(r) } }() - if err = cmd_sock.Connect(cmd_port); err != nil { - panic(err) - } + if len(sub_port) > 0 { + sub_sock, err := ctx.Socket(zmq.Sub) + if err != nil { + panic(err) + } + defer func() { if r:= recover(); r != nil { sub_sock.Close(); panic(r) } }() - sub_sock.Subscribe(subfilter) + sub_sock.Subscribe(subfilter) - if err = sub_sock.Connect(sub_port); err != nil { - panic(err) - } + if err = sub_sock.Connect(sub_port); err != nil { + panic(err) + } - cmd_chans = cmd_sock.ChannelsBuffer(10) - sub_chans = cmd_sock.ChannelsBuffer(10) + sub_chans = sub_sock.ChannelsBuffer(10) + go zmqsHandleError(sub_chans) + } else { + sub_chans = nil + } - go zmqsHandleError(cmd_chans, sub_chans) return } -func zmqsHandleError(cmd_chans, sub_chans *zmq.Channels) { - for { - select { - case cmd_error := <- cmd_chans.Errors(): - cmd_chans.Close() - sub_chans.Close() - panic(cmd_error) - case sub_error := <- sub_chans.Errors(): - cmd_chans.Close() - sub_chans.Close() - panic(sub_error) - } +func zmqsHandleError(chans *zmq.Channels) { + for error := range(chans.Errors()) { + chans.Close() + panic(error) } -} \ No newline at end of file +} diff --git a/go/door_daemon_zmq/zeromq.go b/go/door_daemon_zmq/zeromq.go index a4d8d68..805368e 100644 --- a/go/door_daemon_zmq/zeromq.go +++ b/go/door_daemon_zmq/zeromq.go @@ -16,49 +16,52 @@ func ZmqsInit(cmd_port, pub_port string) (ctx *zmq.Context, cmd_chans, pub_chan if err != nil { panic(err) } - //close only on panic, otherwise leave open: + //close only on later panic, otherwise leave open: defer func(){ if r:= recover(); r != nil { ctx.Close(); panic(r) } }() - cmd_sock, err := ctx.Socket(zmq.Rep) - if err != nil { - panic(err) - } - defer func() { if r:= recover(); r != nil { cmd_sock.Close(); panic(r) } }() + if len(cmd_port) > 0 { + cmd_sock, err := ctx.Socket(zmq.Rep) + if err != nil { + panic(err) + } + defer func() { if r:= recover(); r != nil { cmd_sock.Close(); panic(r) } }() - cmd_sock.SetRecvTimeout(2 * time.Second) - cmd_sock.SetSendTimeout(2 * time.Second) + cmd_sock.SetRecvTimeout(2 * time.Second) + cmd_sock.SetSendTimeout(2 * time.Second) - pub_sock, err := ctx.Socket(zmq.Pub) - if err != nil { - panic(err) + if err = cmd_sock.Bind(cmd_port); err != nil { + panic(err) + } + + cmd_chans = cmd_sock.ChannelsBuffer(10) + go zmqsHandleError(cmd_chans) + } else { + cmd_chans = nil } - defer func() { if r:= recover(); r != nil { pub_sock.Close(); panic(r) } }() - if err = cmd_sock.Bind(cmd_port); err != nil { // "tcp://*:5555" - panic(err) - } + if len(pub_port) > 0 { + pub_sock, err := ctx.Socket(zmq.Pub) + if err != nil { + panic(err) + } + defer func() { if r:= recover(); r != nil { pub_sock.Close(); panic(r) } }() - if err = pub_sock.Bind(pub_port); err != nil { // "tcp://*:5556" - panic(err) + if err = pub_sock.Bind(pub_port); err != nil { + panic(err) + } + + pub_chans = pub_sock.ChannelsBuffer(10) + go zmqsHandleError(pub_chans) + } else { + pub_chans = nil } - cmd_chans = cmd_sock.ChannelsBuffer(10) - pub_chans = cmd_sock.ChannelsBuffer(10) - go zmqsHandleError(cmd_chans, pub_chans) return } -func zmqsHandleError(cmd_chans, pub_chans *zmq.Channels) { - for { - select { - case cmd_error := <- cmd_chans.Errors(): - cmd_chans.Close() - pub_chans.Close() - panic(cmd_error) - case pub_error := <- pub_chans.Errors(): - cmd_chans.Close() - pub_chans.Close() - panic(pub_error) - } +func zmqsHandleError(chans *zmq.Channels) { + for error := range(chans.Errors()) { + chans.Close() + panic(error) } } \ No newline at end of file