MCPcopy Create free account
hub / github.com/boostorg/asio / connect

Method connect

example/cpp11/timeouts/blocking_tcp_client.cpp:39–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37{
38public:
39 void connect(const std::string& host, const std::string& service,
40 std::chrono::steady_clock::duration timeout)
41 {
42 // Resolve the host name and service to a list of endpoints.
43 auto endpoints = tcp::resolver(io_context_).resolve(host, service);
44
45 // Start the asynchronous operation itself. The lambda that is used as a
46 // callback will update the error variable when the operation completes.
47 // The blocking_udp_client.cpp example shows how you can use std::bind
48 // rather than a lambda.
49 boost::system::error_code error;
50 boost::asio::async_connect(socket_, endpoints,
51 [&](const boost::system::error_code& result_error,
52 const tcp::endpoint& /*result_endpoint*/)
53 {
54 error = result_error;
55 });
56
57 // Run the operation until it completes, or until the timeout.
58 run(timeout);
59
60 // Determine whether a connection was successfully established.
61 if (error)
62 throw boost::system::system_error(error);
63 }
64
65 std::string read_line(std::chrono::steady_clock::duration timeout)
66 {

Callers 2

udp_broadcasterMethod · 0.45
mainFunction · 0.45

Calls 2

async_connectFunction · 0.50
resolveMethod · 0.45

Tested by

no test coverage detected