ClickHouse/src/IO/TimeoutSetter.cpp

46 lines
1.3 KiB
C++
Raw Normal View History

2021-03-03 17:47:27 +00:00
#include <IO/TimeoutSetter.h>
2018-09-28 14:53:20 +00:00
2021-10-02 07:13:14 +00:00
#include <base/logger_useful.h>
2018-09-28 14:53:20 +00:00
2021-04-28 03:31:15 +00:00
2018-09-28 14:53:20 +00:00
namespace DB
{
2021-04-28 03:31:15 +00:00
2018-09-28 14:53:20 +00:00
TimeoutSetter::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)
: socket(socket_), send_timeout(send_timeout_), receive_timeout(receive_timeout_)
{
old_send_timeout = socket.getSendTimeout();
old_receive_timeout = socket.getReceiveTimeout();
if (!limit_max_timeout || old_send_timeout > send_timeout)
socket.setSendTimeout(send_timeout);
if (!limit_max_timeout || old_receive_timeout > receive_timeout)
socket.setReceiveTimeout(receive_timeout);
}
2021-04-29 16:11:20 +00:00
TimeoutSetter::TimeoutSetter(Poco::Net::StreamSocket & socket_, Poco::Timespan timeout_, bool limit_max_timeout)
2018-09-28 14:53:20 +00:00
: TimeoutSetter(socket_, timeout_, timeout_, limit_max_timeout)
{
}
TimeoutSetter::~TimeoutSetter()
{
try
{
socket.setSendTimeout(old_send_timeout);
socket.setReceiveTimeout(old_receive_timeout);
}
2021-04-28 03:33:28 +00:00
catch (...)
2018-09-28 14:53:20 +00:00
{
2021-04-28 03:31:15 +00:00
/// Sometimes caught on Mac OS X. This message can be safely ignored.
/// If you are developer using Mac, please debug this error message by yourself.
2021-04-28 03:33:28 +00:00
tryLogCurrentException("Client", "TimeoutSetter: Can't reset timeouts");
2018-09-28 14:53:20 +00:00
}
}
2021-04-28 03:31:15 +00:00
2018-09-28 14:53:20 +00:00
}