Skip to content

Commit f7a7611

Browse files
committed
Merge pull request dhbaird#43 from fourtytoo/master
Enhance poll() to block forever when timeout is negative.
2 parents 47da376 + 4eb06e0 commit f7a7611

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ static pointer from_url(/service/std::string url);
5050
static pointer create_dummy();
5151

5252
// Function to perform actual network send()/recv() I/O:
53-
// (note: if all you need is to recv()/dispatch() messages, then timeout can be
54-
// used to block until a message arrives. By default, when timeout is 0, poll()
55-
// will not block at all.)
53+
// (note: if all you need is to recv()/dispatch() messages, then a
54+
// negative timeout can be used to block until a message arrives.
55+
// By default, when timeout is 0, poll() will not block at all.)
5656
void poll(int timeout = 0); // timeout in milliseconds
5757

5858
// Receive a message, and pass it to callable(). Really, this just looks at

easywsclient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@ class _RealWebSocket : public easywsclient::WebSocket
188188
}
189189
return;
190190
}
191-
if (timeout > 0) {
191+
if (timeout != 0) {
192192
fd_set rfds;
193193
fd_set wfds;
194194
timeval tv = { timeout/1000, (timeout%1000) * 1000 };
195195
FD_ZERO(&rfds);
196196
FD_ZERO(&wfds);
197197
FD_SET(sockfd, &rfds);
198198
if (txbuf.size()) { FD_SET(sockfd, &wfds); }
199-
select(sockfd + 1, &rfds, &wfds, NULL, &tv);
199+
select(sockfd + 1, &rfds, &wfds, 0, timeout > 0 ? &tv : 0);
200200
}
201201
while (true) {
202202
// FD_ISSET(0, &rfds) will be true

0 commit comments

Comments
 (0)