ClickHouse/src/IO/TimeoutSetter.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
917 B
C++
Raw Normal View History

#pragma once
#include <Poco/Net/StreamSocket.h>
2018-09-28 14:53:20 +00:00
#include <Poco/Timespan.h>
namespace DB
{
/// Temporarily overrides socket send/receive timeouts and reset them back into destructor (or manually by calling reset method)
2018-04-04 19:44:28 +00:00
/// If "limit_max_timeout" is true, timeouts could be only decreased (maxed by previous value).
struct TimeoutSetter
{
2018-09-28 14:53:20 +00:00
TimeoutSetter(Poco::Net::StreamSocket & socket_,
2021-04-29 16:11:20 +00:00
Poco::Timespan send_timeout_,
Poco::Timespan receive_timeout_,
2018-09-28 14:53:20 +00:00
bool limit_max_timeout = false);
2021-04-29 16:11:20 +00:00
TimeoutSetter(Poco::Net::StreamSocket & socket_, Poco::Timespan timeout_, bool limit_max_timeout = false);
2018-09-28 14:53:20 +00:00
~TimeoutSetter();
/// Reset timeouts back.
void reset();
Poco::Net::StreamSocket & socket;
Poco::Timespan send_timeout;
2018-09-28 14:53:20 +00:00
Poco::Timespan receive_timeout;
Poco::Timespan old_send_timeout;
Poco::Timespan old_receive_timeout;
bool was_reset = false;
};
}