[zeromq-dev] Query
Quinlan Morake
qmorake at yandex.ru
Fri Jul 4 09:16:27 CEST 2014
Good day everyone,
I figure that perhaps in a later chapter of one of the books, or perhaps by browsing through the source (not at that level yet), I could figure this out; but what is the difference between the following sections of code (if any), and which is preferable / right (if applicable - perhaps under the hood they are the same)
void* sClientInitListener = zmq_socket(sData->zmqContext, ZMQ_REP);
int iPortOp = zmq_bind(sClientInitListener, CLIENT_INITIALIZE_LISTENER);
assert(iPortOp == 0);
void* sServerInitSender = zmq_socket(sData->zmqContext, ZMQ_REQ);
iPortOp = zmq_connect(sServerInitSender, CLIENT_INITIALIZE_SENDER);
assert(iPortOp == 0);
while (*sData->blnRun)
{
char* sSendToServer = s_recv(sClientInitListener);
if (sSendToServer != NULL)
{
s_send(sServerInitSender, sSendToServer);
char* sRepFromServer = s_recv(sServerInitSender);
s_send(sClientInitListener, sRepFromServer);
}
}
zmq_close(sServerInitSender);
zmq_close(sClientInitListener);
VS
void* sClientInitListener = zmq_socket(sData->zmqContext, ZMQ_REP);
int iPortOp = zmq_bind(sClientInitListener, CLIENT_INITIALIZE_LISTENER);
assert(iPortOp == 0);
while (*sData->blnRun)
{
char* sSendToServer = s_recv(sClientInitListener);
if (sSendToServer != NULL)
{
void* sServerInitSender = zmq_socket(sData->zmqContext, ZMQ_REQ);
iPortOp = zmq_connect(sServerInitSender, CLIENT_INITIALIZE_SENDER);
assert(iPortOp == 0);
s_send(sServerInitSender, sSendToServer);
char* sRepFromServer = s_recv(sServerInitSender);
zmq_close(sServerInitSender);
s_send(sClientInitListener, sRepFromServer);
}
}
zmq_close(sClientInitListener);
My understanding is that in the first instance; after s_recv(sClientInitListener), we’re in a different thread than that which executed “s_recv(sClientInitListener)” so its a different thread that’s executing the “s_send(sServerInitSender..” which would mean I’m sharing sockets over threads, which I shouldn’t be doing. But I’m almost certain that I saw something similar being done in examples and in the books (Pg 18 O’ Reily ZeroMQ for example). So I must be understanding something incorrectly.
Regards,
Quinlan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140704/7358816d/attachment.htm>
More information about the zeromq-dev
mailing list