Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #393 from hurricaneLTG/master
Browse files Browse the repository at this point in the history
Handle the EINTR return code by ignoreing it and trying what ever we were doing again.
  • Loading branch information
Ron Korving committed Feb 3, 2015
2 parents 6bef666 + fe55fe1 commit f2e4a1b
Showing 1 changed file with 48 additions and 18 deletions.
66 changes: 48 additions & 18 deletions binding.cc
Expand Up @@ -360,10 +360,16 @@ namespace zmq {
zmq_pollitem_t item = {socket_, 0, ZMQ_POLLIN, 0};
if (pending_ > 0)
item.events |= ZMQ_POLLOUT;

int rc = zmq_poll(&item, 1, 0);
if (rc < 0) {
throw std::runtime_error(ErrorMessage());
while (true) {
int rc = zmq_poll(&item, 1, 0);
if (rc < 0) {
if (zmq_errno()==EINTR) {
continue;
}
throw std::runtime_error(ErrorMessage());
} else {
break;
}
}
return item.revents & item.events;
}
Expand Down Expand Up @@ -539,9 +545,17 @@ namespace zmq {
Handle<Value> Socket::GetSockOpt(int option) {
T value = 0;
size_t len = sizeof(T);
if (zmq_getsockopt(socket_, option, &value, &len) < 0) {
NanThrowError(ExceptionFromError());
return NanUndefined();
while (true) {
int rc = zmq_getsockopt(socket_, option, &value, &len);
if (rc < 0) {
if(zmq_errno()==EINTR) {
continue;
}
NanThrowError(ExceptionFromError());
return NanUndefined();
} else {
break;
}
}
return NanNew<Number>(value);
}
Expand Down Expand Up @@ -968,13 +982,22 @@ namespace zmq {
GET_SOCKET(args);

IncomingMessage msg;
while (true) {
int rc;
#if ZMQ_VERSION_MAJOR == 2
if (zmq_recv(socket->socket_, msg, flags) < 0)
return NanThrowError(ErrorMessage());
rc = zmq_recv(socket->socket_, msg, flags);
#else
if (zmq_recvmsg(socket->socket_, msg, flags) < 0)
return NanThrowError(ErrorMessage());
rc = zmq_recvmsg(socket->socket_, msg, flags);
#endif
if (rc < 0) {
if (zmq_errno()==EINTR) {
continue;
}
return NanThrowError(ErrorMessage());
} else {
break;
}
}
NanReturnValue(msg.GetBuffer());
}

Expand Down Expand Up @@ -1072,17 +1095,24 @@ namespace zmq {
char * cp = (char *)zmq_msg_data(&msg);
const char * dat = Buffer::Data(buf);
std::copy(dat, dat + len, cp);

while (true) {
int rc;
#if ZMQ_VERSION_MAJOR == 2
if (zmq_send(socket->socket_, &msg, flags) < 0)
return NanThrowError(ErrorMessage());
rc = zmq_send(socket->socket_, &msg, flags);
#elif ZMQ_VERSION_MAJOR == 3
if (zmq_sendmsg(socket->socket_, &msg, flags) < 0)
return NanThrowError(ErrorMessage());
rc = zmq_sendmsg(socket->socket_, &msg, flags);
#else
if (zmq_msg_send(&msg, socket->socket_, flags) < 0)
return NanThrowError(ErrorMessage());
rc = zmq_msg_send(&msg, socket->socket_, flags);
#endif
if (rc < 0){
if (zmq_errno()==EINTR) {
continue;
}
return NanThrowError(ErrorMessage());
} else {
break;
}
}
#endif // zero copy / copying version

NanReturnUndefined();
Expand Down

0 comments on commit f2e4a1b

Please sign in to comment.