Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to actually handle a graceful close? #254

Open
Gandalf1783 opened this issue Jan 24, 2024 · 1 comment
Open

How to actually handle a graceful close? #254

Gandalf1783 opened this issue Jan 24, 2024 · 1 comment

Comments

@Gandalf1783
Copy link

Gandalf1783 commented Jan 24, 2024

I have a while-loop which is receiving via socket->receive(message);.

I call another function inside the same class (but from a different thread) which tells the while loop to end.
Additonally, I have to close the sockets so the term/destroy on the context is not erroring out.

After both socket operations, I just get "Ressource temporarily unavailable".
Why is that?
The sockets gets bound to the same endpoint, but cannot be closed?

Of course, in the other Thread its still running socket->receive(message), but that one should stop once I call zmq_ctx_term() according to the docs.

TLDR;: How do I actually close zmqpp gracefully from another thread?

@Gandalf1783
Copy link
Author

This is the current code that I'm using to try to close the socket gracefully:

printf("Closing Socket: \n");
 std::string endpoint = this->socket->get<std::string>(zmqpp::socket_option::last_endpoint);

 std::cout << "Unbinding: " << endpoint << std::endl;

 this->socket->unbind(endpoint);
 printf("ERRNO: %s\n", zmq_strerror(zmq_errno()));

 zmq_close(*this->socket.get());
 printf("ERRNO: %s\n", zmq_strerror(zmq_errno()));    

 printf("Destroy Context: \n");
 
 zmq_ctx_term(*(this->context.get()));
 printf("ERRNO: %s\n", zmq_strerror(zmq_errno()));

I understand that also socket->term(); exists, but it doesnt work either way.

The current output to the code above is:

Closing Socket: 
Unbinding: tcp://127.0.0.1:5555
ERRNO: Resource temporarily unavailable
ERRNO: Resource temporarily unavailable
Destroy Context: 
terminate called after throwing an instance of 'zmqpp::zmq_internal_exception'
  what():  Context was terminated
[2]    98074 IOT instruction (core dumped)

This does seem like the way to go, but it isnt working well....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant