Skip to content

Commit 89311fd

Browse files
client: check ready futures in waitAll and waitCount before waiting
Instead of unconditionally waiting we can first check the post-condition of the waiting. Closes #133
1 parent 77db5f9 commit 89311fd

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Client/Connector.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,6 @@ Connector<BUFFER, NetProvider>::waitAll(Connection<BUFFER, NetProvider> &conn,
266266
timer.start();
267267
size_t last_not_ready = 0;
268268
while (!conn.hasError()) {
269-
if (m_NetProvider.wait(timer.timeLeft()) != 0) {
270-
conn.setError(std::string("Failed to poll: ") +
271-
strerror(errno), errno);
272-
return -1;
273-
}
274269
if (connectionDecodeResponses(conn) != 0)
275270
return -1;
276271
bool finish = true;
@@ -283,6 +278,10 @@ Connector<BUFFER, NetProvider>::waitAll(Connection<BUFFER, NetProvider> &conn,
283278
}
284279
if (finish)
285280
return 0;
281+
if (m_NetProvider.wait(timer.timeLeft()) != 0) {
282+
conn.setError(std::string("Failed to poll: ") + strerror(errno), errno);
283+
return -1;
284+
}
286285
if (timer.isExpired())
287286
break;
288287
}
@@ -325,15 +324,15 @@ Connector<BUFFER, NetProvider>::waitCount(Connection<BUFFER, NetProvider> &conn,
325324
timer.start();
326325
size_t ready_futures = conn.getFutureCount();
327326
while (!conn.hasError()) {
327+
if (connectionDecodeResponses(conn) != 0)
328+
return -1;
329+
if ((conn.getFutureCount() - ready_futures) >= future_count)
330+
return 0;
328331
if (m_NetProvider.wait(timer.timeLeft()) != 0) {
329332
conn.setError(std::string("Failed to poll: ") +
330333
strerror(errno), errno);
331334
return -1;
332335
}
333-
if (connectionDecodeResponses(conn) != 0)
334-
return -1;
335-
if ((conn.getFutureCount() - ready_futures) >= future_count)
336-
return 0;
337336
if (timer.isExpired())
338337
break;
339338
}

0 commit comments

Comments
 (0)