Go ZMQ4 – Close a socket blocked on Recv?

huangapple go评论73阅读模式
英文:

Go ZMQ4 - Close a socket blocked on Recv?

问题

我正在使用这个库:https://github.com/pebbe/zmq4 来进行Go语言的ZeroMQ绑定。

我的问题是,如何安全地关闭一个正在等待消息的套接字?我在考虑为每个套接字创建一个新的上下文,然后我可以终止该上下文。

但是,pebbe/zmq4库似乎不允许我创建一个新的上下文。

谢谢你的帮助。

英文:

I am using this library: https://github.com/pebbe/zmq4 for Go bindings of ZeroMQ.

My question is, how do I safely close a socket that's waiting for a message? I was thinking of creating a new context for every socket and then I could just terminate the context.

But the pebbe/zmq4 library doesn't allow me to create a new context (or so it seems to me).

Thanks for helping.

答案1

得分: 0

我正在采纳我其中一位教授的简单而有效的建议。

在关闭时,我会向套接字发送一个独特的终止代码,并等待套接字读取并关闭自身。

英文:

I am going with a simple yet effective suggestion from one of my professors.

While closing, I send a unique termination code to the socket and wait till the socket reads it and closes itself.

huangapple
  • 本文由 发表于 2014年1月27日 20:53:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/21381441.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定