简体   繁体   English

丢弃NetMQ套接字后无法重用端点

[英]Cannot reuse an endpoint after NetMQ socket disposal

In my application I am creating and disposing NetMQ sockets. 在我的应用程序中,我正在创建和处置NetMQ套接字。 I have noticed that I cannot bind to an endpoint for some time after the disposal of the previous socket bound to that endpoint. 我注意到,在处置了先前绑定到该端点的套接字后的一段时间内,我无法绑定到该端点。 A minimal example: 一个最小的例子:

const string endpoint = "tcp://127.0.0.1:1234";

using (var publisher = new PublisherSocket())
    publisher.Bind(endpoint);

using (var publisher = new PublisherSocket())
    publisher.Bind(endpoint); //throws a NetMQException: "Unknown error (0xffffffff)"

The Linger option is set to 0, but I still have to wait (up to several seconds in my experiments) before the second bind. Linger选项设置为0,但是在第二个绑定之前,我仍然必须等待(在实验中可能要花费几秒钟)。

I could add a Thread.Sleep or some other delaying instruction, but this is neither robust nor elegant. 我可以添加Thread.Sleep或其他一些延迟指令,但这既不健壮也不优雅。

Is this a bug? 这是错误吗? If not, what is the proper way of making sure that I can already bind to an endpoint? 如果没有,确保我已经可以绑定到端点的正确方法是什么?

Not a bug, the dispose of a socket is async and happen in a background thread. 这不是错误,套接字的处理是异步的,发生在后台线程中。 You can try and call Unbind before the dispose, it might be faster. 您可以尝试在处置之前致电Unbind,这可能会更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM