Skip to content

Commit

Permalink
Merge pull request #2360 from nexcvon/patch-2
Browse files Browse the repository at this point in the history
Problem: Assertion failed in zmq::signaler_t::send
  • Loading branch information
bluca authored Mar 3, 2017
2 parents 07d904a + bcf7577 commit 34be53d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/signaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,13 @@ void zmq::signaler_t::send ()
errno_assert (sz == sizeof (inc));
#elif defined ZMQ_HAVE_WINDOWS
unsigned char dummy = 0;
int nbytes = ::send (w, (char *) &dummy, sizeof (dummy), 0);
wsa_assert (nbytes != SOCKET_ERROR);
zmq_assert (nbytes == sizeof (dummy));
while (true) {
int nbytes = ::send (w, (char*) &dummy, sizeof (dummy), 0);
if (unlikely (nbytes == SOCKET_ERROR))
continue;
zmq_assert (nbytes == sizeof (dummy));
break;
}
#else
unsigned char dummy = 0;
while (true) {
Expand Down

3 comments on commit 34be53d

@a4z
Copy link
Contributor

@a4z a4z commented on 34be53d Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short question: if send starts to report errors, will this not lead into an endless loop?

@bluca
Copy link
Member Author

@bluca bluca commented on 34be53d Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what SOCKET_ERROR means on Windows, I assumed it was the same as EINTR on *nix from the commit message
@nexcvon any comment?

@10-5
Copy link
Contributor

@10-5 10-5 commented on 34be53d Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SOCKET_ERROR on Windows is not the same as EINTR on *nix. The wsa_assert statement should be retained. I sent another PR #2362 to fix this.

On Windows, when error happens, send() returns SOCKET_ERROR, and WSAGetLastError() should be called to get the error code.

In this problem:

  1. send() returns SOCKET_ERROR
  2. WSAGetLastError() returns WSAEWOULDBLOCK
  3. zmq_assert fails.

Please sign in to comment.