Socket#recv()的内容如下:
返回:.错误为空。
我怎么知道是什么错误?我想专门处理EAGAIN。
发布于 2016-01-07 20:30:50
我在这里所知甚少,但从表面上看,答案可能是:
“如果Socket#recv()返回null,而没有引发ZMQException,则会发生EAGAIN错误。”
我遵循了方法调用,并在Socket.cpp中到达了Socket.cpp,在第83项上变得有趣了:
rc = zmq_recv (socket, message, flags);
int err = zmq_errno();
if (rc < 0 && err == EAGAIN) {
rc = zmq_msg_close (message);
err = zmq_errno();
if (rc != 0) {
raise_exception (env, err);
return NULL;
}
return NULL;
}
if (rc < 0) {
raise_exception (env, err);
rc = zmq_msg_close (message);
err = zmq_errno();
if (rc != 0) {
raise_exception (env, err);
return NULL;
}
return NULL;
}
return message;我在这里读到的是,如果出了问题,您可以在Java中得到一个ZMQException,除非错误是EAGAIN,而zmq_msg_close没有出错(我不知道zmq_msg_close做了什么,但我假设它很少出错)。
但我没有环境来测试这一点,我也不太明白raise_exception是如何工作的(util.cpp中的源代码):如果在相同的代码路径中引发/抛出两个异常(例如,当err不是EAGAIN和rc < 0时),而您只能捕获一个运行时异常,那么会发生什么情况?
另外,此承诺于2015年5月15日添加了对EAGAIN错误代码的支持。
发布于 2016-01-13 08:21:05
源代码是:
/**
* Receive a message.
*
* @return the message received, as an array of bytes; null on error.
*/
public final byte[] recv()
{
return recv(0);
}
/**
* Receive a message.
*
* @param flags
* the flags to apply to the receive operation.
* @return the message received, as an array of bytes; null on error.
*/
public final byte[] recv(int flags)
{
zmq.Msg msg = base.recv(flags);
if (msg != null) {
return msg.data();
}
mayRaise();
return null;
}
private void mayRaise()
{
int errno = base.errno();
if (errno != 0 && errno != zmq.ZError.EAGAIN) {
throw new ZMQException(errno);
}
} 因此,可以更改recv(int标志)和mayRaise()函数。
https://stackoverflow.com/questions/34028634
复制相似问题