poll() blocks for ever when timeout is negative.
This commit is contained in:
@@ -50,9 +50,9 @@ static pointer from_url(std::string url);
|
|||||||
static pointer create_dummy();
|
static pointer create_dummy();
|
||||||
|
|
||||||
// Function to perform actual network send()/recv() I/O:
|
// Function to perform actual network send()/recv() I/O:
|
||||||
// (note: if all you need is to recv()/dispatch() messages, then timeout can be
|
// (note: if all you need is to recv()/dispatch() messages, then a
|
||||||
// used to block until a message arrives. By default, when timeout is 0, poll()
|
// negative timeout can be used to block until a message arrives.
|
||||||
// will not block at all.)
|
// By default, when timeout is 0, poll() will not block at all.)
|
||||||
void poll(int timeout = 0); // timeout in milliseconds
|
void poll(int timeout = 0); // timeout in milliseconds
|
||||||
|
|
||||||
// Receive a message, and pass it to callable(). Really, this just looks at
|
// Receive a message, and pass it to callable(). Really, this just looks at
|
||||||
|
|||||||
+2
-2
@@ -188,7 +188,7 @@ class _RealWebSocket : public easywsclient::WebSocket
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (timeout > 0) {
|
if (timeout != 0) {
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
fd_set wfds;
|
fd_set wfds;
|
||||||
timeval tv = { timeout/1000, (timeout%1000) * 1000 };
|
timeval tv = { timeout/1000, (timeout%1000) * 1000 };
|
||||||
@@ -196,7 +196,7 @@ class _RealWebSocket : public easywsclient::WebSocket
|
|||||||
FD_ZERO(&wfds);
|
FD_ZERO(&wfds);
|
||||||
FD_SET(sockfd, &rfds);
|
FD_SET(sockfd, &rfds);
|
||||||
if (txbuf.size()) { FD_SET(sockfd, &wfds); }
|
if (txbuf.size()) { FD_SET(sockfd, &wfds); }
|
||||||
select(sockfd + 1, &rfds, &wfds, NULL, &tv);
|
select(sockfd + 1, &rfds, &wfds, 0, timeout > 0 ? &tv : 0);
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
// FD_ISSET(0, &rfds) will be true
|
// FD_ISSET(0, &rfds) will be true
|
||||||
|
|||||||
Reference in New Issue
Block a user