Reputation: 674
I'm writing a small test app using ZeroMQ
.
One test scenario I have is when there is no server running to connect to.
So, I'm passing ZMQ_DONTWAIT
to zmq_recv()
in that scenario expecting an error of EAGAIN
but instead getting errno
value of 0.
Sample client code below:
int rc;
void *context = zmq_ctx_new();
void *requester = zmq_socket(context, ZMQ_REQ);
int nLingerOption = 0;
rc = zmq_setsockopt(requester, ZMQ_LINGER, &nLingerOption, sizeof(nLingerOption));
rc = zmq_connect(requester, "tcp://127.0.0.1:5555");
int nSendLen = zmq_send(requester, "M", 1, 0);
char buffer[1000];
int nRecvLen = zmq_recv(requester, buffer, sizeof(buffer)-1, ZMQ_DONTWAIT);
if( nRecvLen < 0 )
printf("errno = %d\n", errno);
Why would the output be 0
instead of EAGAIN
(defined as 11 on my system).
EDIT: This is running ZeroMQ version 4.1
Upvotes: 0
Views: 2041
Reputation: 13766
The answer is hiding in your windows
tag (thanks for including that). Relevant: http://api.zeromq.org/4-1:zmq-errno
Specifically:
The zmq_errno() function is provided to assist users on non-POSIX systems who are experiencing issues with retrieving the correct value of errno directly. Specifically, users on Win32 systems whose application is using a different C run-time library from the C run-time library in use by ØMQ will need to use zmq_errno() for correct operation.
You should be using zmq_errno()
as opposed to accessing errno
directly.
Upvotes: 1