Skip to content

Commit

Permalink
Client: fix interpretation of zero timeout value in NetProviders
Browse files Browse the repository at this point in the history
As per the `Connector::wait*` API documentation, the zero timeout value
means an infinite timeout:
> `timeout = 0` means the method is polling the future until the response
> is ready. [1]

The zero timeout value is completely misinterpreted in the
`LibevNetProvider` — a timeout timer should only be created if the timeout
is non-zero.

The zero timeout value is oddly interpreted in the `LibevNetProvider` — the
corresponding infinite timeout value in the epoll API is `-1`.

Closes #61

1. https://www.tarantool.io/en/doc/latest/book/connectors/cxx/tntcxx_api/#_CPPv44waitR10ConnectionI6BUFFER11NetProviderE5rid_ti
  • Loading branch information
CuriousGeorgiy committed Nov 15, 2023
1 parent 8eb7819 commit 83edc79
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Client/EpollNetProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class EpollNetProvider {
int wait(int timeout);

private:
static constexpr size_t DEFAULT_TIMEOUT = 100;
static constexpr int TIMEOUT_INFINITY = -1;
static constexpr size_t EPOLL_EVENTS_MAX = 128;

//return 0 if all data from buffer was processed (sent or read);
Expand Down Expand Up @@ -261,7 +261,7 @@ EpollNetProvider<BUFFER, Stream>::wait(int timeout)
{
assert(timeout >= 0);
if (timeout == 0)
timeout = DEFAULT_TIMEOUT;
timeout = TIMEOUT_INFINITY;
LOG_DEBUG("Network engine wait for ", timeout, " milliseconds");
/* Send pending requests. */
for (auto conn = m_Connector.m_ReadyToSend.begin();
Expand Down
6 changes: 4 additions & 2 deletions src/Client/LibevNetProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,10 @@ int
LibevNetProvider<BUFFER, Stream>::wait(int timeout)
{
assert(timeout >= 0);
ev_timer_init(&m_TimeoutWatcher, &timeout_cb, timeout / MILLISECONDS, 0 /* repeat */);
ev_timer_start(m_Loop, &m_TimeoutWatcher);
if (timeout > 0) {
ev_timer_init(&m_TimeoutWatcher, &timeout_cb, timeout / MILLISECONDS, 0 /* repeat */);
ev_timer_start(m_Loop, &m_TimeoutWatcher);
}
/* Queue pending connections to be send. */
for (auto conn = m_Connector.m_ReadyToSend.begin();
conn != m_Connector.m_ReadyToSend.end();) {
Expand Down

0 comments on commit 83edc79

Please sign in to comment.