[zeromq-dev] czmq v3.0.0: zsys_set_logsender, bind vs connect issue - tentative patch
Pieter Hintjens
ph at imatix.com
Wed May 20 14:12:33 CEST 2015
Swapping bind/connect by default breaks the API contract. However we
could use the CZMQ bind/connect syntax, see zsock_attach().
On Wed, May 20, 2015 at 10:16 AM, Michael Haberler <mail17 at mah.priv.at> wrote:
>
>> Am 20.05.2015 um 08:52 schrieb Pieter Hintjens <ph at imatix.com>:
>>
>> Right, now we have to choose between multiple processes or multiple
>> loggers... Can you use distinct endpoints per process?
>
> I could in theory - at the expense of (IMU uselessly) complicating the cause - the log demon starts before all other processes and would have to guess/prepare several sockets?
>
> any issues with swapping bind to connect?
>
> - Michael
>
>>
>> On Wed, May 20, 2015 at 7:52 AM, Michael Haberler <mail17 at mah.priv.at> wrote:
>>> czmq: zsys_set_logsender() currently zmq_bind()s to an endpoint.
>>>
>>> That is fine in the inproc testcase as per zsys.c but fails if one has several processes which would like to log over an IPC socket, to say an existing log daemon. In this case the a second process doing zsys_set_logsender(ipc endpoint) fails the bind:
>>>
>>> // Bind to specified endpoint
>>> int rc = zmq_bind (s_logsender, endpoint);
>>> assert (rc == 0); <------ fail
>>>
>>> this would work if zsys_set_logsender() did a connect instead, and only the log subscriber did a bind.
>>>
>>>
>>> the following tentative patch cures the issue - should I prepare a PR?
>>>
>>> @@ -1315,11 +1315,11 @@ zsys_set_logsender (const char *endpoint)
>>> if (!s_logsender) {
>>> s_logsender = zsys_socket (ZMQ_PUB, NULL, 0);
>>> assert (s_logsender);
>>> }
>>> // Bind to specified endpoint
>>> - int rc = zmq_bind (s_logsender, endpoint);
>>> + int rc = zmq_connect (s_logsender, endpoint);
>>> assert (rc == 0);
>>> }
>>> else
>>> if (s_logsender) {
>>> zsys_close (s_logsender, NULL, 0);
>>> @@ -1551,11 +1551,11 @@ zsys_test (bool verbose)
>>> // Test logging system
>>> zsys_set_logident ("czmq_selftest");
>>> zsys_set_logsender ("inproc://logging");
>>> void *logger = zsys_socket (ZMQ_SUB, NULL, 0);
>>> assert (logger);
>>> - rc = zsocket_connect (logger, "inproc://logging");
>>> + rc = zsocket_bind (logger, "inproc://logging");
>>> assert (rc == 0);
>>> rc = zmq_setsockopt (logger, ZMQ_SUBSCRIBE, "", 0);
>>> assert (rc == 0);
>>>
>>> if (verbose) {
>>>
>>>
>>> _______________________________________________
>>> zeromq-dev mailing list
>>> zeromq-dev at lists.zeromq.org
>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
More information about the zeromq-dev
mailing list