[zeromq-dev] zmq_socket_monitor blocks port of REP/REQ TCP/IP in C

Björn Kuhlbrodt bjoern.kuhlbrodt at gpsolar.com
Thu Jan 16 16:59:41 CET 2014


I' trying to use zmq_socket_monitor to get notice when my TCP/IP socket is disconnected. I do not send much but the user would like to know when something goes offline asap.
All works fine up to the point where I stop the socket and (maybe a while later) start a new one. Here's what I got:

Main thread:
m_pZContext = zmq_ctx_new();
Start comm. threads
Stop comm.  Threads

zmq_ctx_term (m_pZContext); //_always crashes!

Comm threads (n):

void* pZReceiveSocket = zmq_socket(m_pZContext, ZMQ_REP);

int result = zmq_bind(pZReceiveSocket, connection);

int rc = zmq_socket_monitor(pZReceiveSocket, monitor.c_str(), ZMQ_EVENT_ALL);
Start monitor threads
Do comm until stop signal
Stop monitor threads

int rc = zmq_unbind(pZReceiveSocket, connection);

ASSERT(rc == 0);

rc = zmq_close(pZReceiveSocket);

ASSERT(rc == 0);

Monitor threads (one per comm. Thread):

rc = zmq_connect (m_MonitorSocket, monitor.c_str());
handle events until stop signal

rc = zmq_disconnect (m_MonitorSocket, monitor.c_str());

ASSERT (rc == 0);

int rc = zmq_close (m_MonitorSocket);

ASSERT (rc == 0);

All threads end gracefully, all sockets have a  low LINGER, but zmq_ctx_term always crashes deep in libzmq.

If I don't use zmq_ctx_term the next time I try to open I get address in use.

Only way out: don't use zmq_socket_monitor and all works fine. That's too bad, tough as I'd really like to know asap when the connection is gone.

Any Ideas? Need more Input?

Best Regards

Dr. Björn Kuhlbrodt
Senior Software Developer
GP Inspect GmbH

Tel: +49 89 750778 4729
Fax: +49 89 750778 4710
E-Mail: bjoern.kuhlbrodt at gpsolar.com<mailto:bjoern.kuhlbrodt at gpsolar.com>

GP Inspect GmbH | Hainbuchenring 9-11 | 82061 Neuried | Deutschland
Geschäftsführer | Christian Probst, Dr. Eric Rüland, Enis Ersü, Martin Heinrich
Amtsgericht München | HRB 173887

A company of ISRA VISION Group

This e-mail may contain material that is confidential, privileged and for the sole use of the intended recipient. Any review, reliance or
distribution by others or forwarding without express permission is strictly prohibited. If you are not the intended recipient, please
contact the sender and delete all copies. GP Inspect GmbH, ISRA VISION AG, its branches and subsidiaries herewith exclude
any liability for third-party information recognizably contained in this email or its attachments. Third-party information does not
necessarily reflect the opinion of GP Inspect GmbH or, ISRA VISION AG.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140116/839f2208/attachment.htm>

More information about the zeromq-dev mailing list