mirror of https://github.com/Icinga/icinga2.git
Connect(): add non-async overload
This commit is contained in:
parent
dc0288fef8
commit
d1e87bdc45
|
@ -27,6 +27,35 @@ public:
|
|||
void Connect(const String& node, const String& service);
|
||||
};
|
||||
|
||||
template<class Socket>
|
||||
void Connect(Socket& socket, const String& node, const String& service)
|
||||
{
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
tcp::resolver resolver (socket.get_io_service());
|
||||
tcp::resolver::query query (node, service);
|
||||
auto result (resolver.resolve(query));
|
||||
auto current (result.begin());
|
||||
|
||||
for (;;) {
|
||||
try {
|
||||
socket.open(current->endpoint().protocol());
|
||||
socket.set_option(tcp::socket::keep_alive(true));
|
||||
socket.connect(current->endpoint());
|
||||
|
||||
break;
|
||||
} catch (const std::exception&) {
|
||||
if (++current == result.end()) {
|
||||
throw;
|
||||
}
|
||||
|
||||
if (socket.is_open()) {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class Socket>
|
||||
void Connect(Socket& socket, const String& node, const String& service, boost::asio::yield_context yc)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue