Closed fengmao31 closed 1 year ago
In fact, in my real application, I want to use shutdown to stop the rec in the subthread. but one problem is throw error_t below, another problem is the zmq_errno() is independent in different thread.
I dont understand what the problem is exactly. What you call shutdown all current and further operations will throw error with ETERM code (which you can catch and check for).
I want to use context.shutdown to close the recv() in another thread or that recv thread will block ctrl +c in the terminal. When I use ctrl + c to exit the program, the terminal will show the error.
zmq_ctx_shutdown:
terminate called after throwing an instance of 'zmq::error_t'
what(): Context was terminated
I find it is because the throw errot_t in cppzmq.
though the doc about zmq say the context.shutdown will free the blocked recv() and return with error EAGAIN.
but in the recv fuction the zmq_errno()
return 156384765 not EAGAIN.
Maybe it is becuse the recv is free and produce new error. The new return cover the EAGAIN. So the if(zmq_errno() == EAGAIN)
will not work. The throw errot_t will show the error in the terminal and the ctrl+c cannot exit the program normally.
According to this http://api.zeromq.org/master:zmq-ctx-shutdown all operations will return ETERM.
根据这个http://api.zeromq.org/master:zmq-ctx-shutdown,所有操作都将返回ETERM。
but in fact, the error from recv function will cover the ETERM. I shut down the context in the main thread. The recv function in the subthread will throw the error 156384765.
That is ETERM.
那就是ETERM。
Yes. You are right. But throw error_t() in the recv function will make the process cannot exit normally. Do you have good idea? I use try catch to solve it. But it is not a beautiful handling.
I see nothing wrong with try catch, that is how I do it.
Why it is hard to find the try catch handling in the opening source respository in github or business respository
The zmq_ctx_shutdown() function shall shutdown the ØMQ context context.
Context shutdown will cause any blocking operations currently in progress on sockets open within context to return immediately with an error code of ETERM.
it means this way will produce errors. but the zmq_errno() return 156384765 no EAGAIN.