Skip to content

Commit a0e6e03

Browse files
client: handle connections with ready responses in waitAny
Currently, `waitAny` does not account for connections that already have ready responses. Let's handle this by going through the set of owned connections and checking them for ready responses. We should do this before the timer start, since the checking overhead should not be accounted for the waiting time. Closes #132
1 parent a749436 commit a0e6e03

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/Client/Connection.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ struct ConnectionImpl
8686
void setError(const std::string &msg, int errno_ = 0);
8787
bool hasError() const;
8888

89+
size_t getFutureCount() const;
90+
8991
BUFFER &getInBuf();
9092
BUFFER &getOutBuf();
9193

@@ -162,6 +164,13 @@ ConnectionImpl<BUFFER, NetProvider>::hasError() const
162164
return error.has_value();
163165
}
164166

167+
template <class BUFFER, class NetProvider>
168+
size_t
169+
ConnectionImpl<BUFFER, NetProvider>::getFutureCount() const
170+
{
171+
return futures.size();
172+
}
173+
165174
template <class BUFFER, class NetProvider>
166175
BUFFER &
167176
ConnectionImpl<BUFFER, NetProvider>::getInBuf()
@@ -460,7 +469,7 @@ template<class BUFFER, class NetProvider>
460469
size_t
461470
Connection<BUFFER, NetProvider>::getFutureCount() const
462471
{
463-
return impl->futures.size();
472+
return impl->getFutureCount();
464473
}
465474

466475
template<class BUFFER, class NetProvider>

src/Client/Connector.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ Connector<BUFFER, NetProvider>::waitAny(int timeout)
363363
TNT_LOG_DEBUG("waitAny() called on connector without connections");
364364
return std::nullopt;
365365
}
366+
for (auto *conn : m_Connections) {
367+
if (conn->getFutureCount() != 0)
368+
return conn;
369+
}
366370
Timer timer{timeout};
367371
timer.start();
368372
while (m_ReadyToDecode.empty()) {

test/ClientTest.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,13 +1405,10 @@ test_wait(Connector<BUFFER, NetProvider> &client)
14051405
/* FIXME(gh-143): test solely that we check future readiness before waiting. */
14061406
fail_unless(client.waitCount(conn, 0) == 0);
14071407
conn.getResponse(f);
1408-
/* FIXME(gh-132): waitAny does not check connections for ready futures. */
1409-
#if 0
14101408
f = conn.ping();
14111409
fail_unless(client.wait(conn, f, WAIT_TIMEOUT) == 0);
1412-
fail_unless(client.waitAny(conn).has_value());
1410+
fail_unless(client.waitAny().has_value());
14131411
conn.getResponse(f);
1414-
#endif
14151412

14161413
#ifdef __linux__
14171414
TEST_CASE("wait methods internal wait failure (gh-121)");

0 commit comments

Comments
 (0)