diff options
author | Jonathan Reams <jbreams@mongodb.com> | 2018-02-20 14:33:42 -0500 |
---|---|---|
committer | Jonathan Reams <jbreams@mongodb.com> | 2018-03-02 11:07:01 -0500 |
commit | b2d8bd06318e1fddf4f1579084bbda4fb556c176 (patch) | |
tree | f591c41a0100dc85b51177396e80b946822aa712 /src/third_party | |
parent | 975d539ae068bd27ebb478b6f3673b89d2ad6beb (diff) | |
download | mongo-b2d8bd06318e1fddf4f1579084bbda4fb556c176.tar.gz |
SERVER-33300 Integrate TransportLayer with DBClient
Diffstat (limited to 'src/third_party')
5 files changed, 72 insertions, 9 deletions
diff --git a/src/third_party/asio-master/asio/include/asio/basic_socket.hpp b/src/third_party/asio-master/asio/include/asio/basic_socket.hpp index 43430161270..d224bac0a83 100644 --- a/src/third_party/asio-master/asio/include/asio/basic_socket.hpp +++ b/src/third_party/asio-master/asio/include/asio/basic_socket.hpp @@ -760,7 +760,7 @@ public: peer_endpoint.protocol(), ec); asio::detail::throw_error(ec, "connect"); } - this->get_service().connect(this->get_implementation(), peer_endpoint, ec); + this->get_service().connect(this->get_implementation(), peer_endpoint, -1, ec); asio::detail::throw_error(ec, "connect"); } @@ -805,7 +805,63 @@ public: } } - this->get_service().connect(this->get_implementation(), peer_endpoint, ec); + this->get_service().connect(this->get_implementation(), peer_endpoint, -1, ec); + ASIO_SYNC_OP_VOID_RETURN(ec); + } + + /// Connect the socket to the specified endpoint with a timeout. + /** + * This function is used to connect a socket to the specified remote endpoint. + * The function call will block until the connection is successfully made or + * an error occurs. + * + * The socket is automatically opened if it is not already open. If the + * connect fails, and the socket was automatically opened, the socket is + * not returned to the closed state. + * + * Passing a timeout of less than zero will return an invalid_argument error. + * + * @param peer_endpoint The remote endpoint to which the socket will be + * connected. + * + * @param timeout The time to wait for the connection before failing + * + * @param ec Set to indicate what error occurred, if any. + * + * @par Example + * @code + * asio::ip::tcp::socket socket(io_context); + * asio::ip::tcp::endpoint endpoint( + * asio::ip::address::from_string("1.2.3.4"), 12345); + * asio::error_code ec; + * socket.connect(endpoint, std::chrono::seconds{30}, ec); + * if (ec) + * { + * // An error occurred. + * } + * @endcode + */ + template <typename Duration> + ASIO_SYNC_OP_VOID connect(const endpoint_type& peer_endpoint, + Duration timeout, asio::error_code& ec) + { + if (!is_open()) + { + this->get_service().open(this->get_implementation(), + peer_endpoint.protocol(), ec); + if (ec) + { + ASIO_SYNC_OP_VOID_RETURN(ec); + } + } + + auto timeout_ms = std::chrono::duration_cast<std::chrono::milliseconds>(timeout); + if (timeout_ms.count() < 0) + { + ec = asio::error::invalid_argument; + ASIO_SYNC_OP_VOID_RETURN(ec); + } + this->get_service().connect(this->get_implementation(), peer_endpoint, timeout_ms.count(), ec); ASIO_SYNC_OP_VOID_RETURN(ec); } diff --git a/src/third_party/asio-master/asio/include/asio/detail/impl/socket_ops.ipp b/src/third_party/asio-master/asio/include/asio/detail/impl/socket_ops.ipp index 2f89889fac8..58ad04ea66f 100644 --- a/src/third_party/asio-master/asio/include/asio/detail/impl/socket_ops.ipp +++ b/src/third_party/asio-master/asio/include/asio/detail/impl/socket_ops.ipp @@ -491,7 +491,7 @@ int connect(socket_type s, const socket_addr_type* addr, } void sync_connect(socket_type s, const socket_addr_type* addr, - std::size_t addrlen, asio::error_code& ec) + std::size_t addrlen, int timeout_ms, asio::error_code& ec) { // Perform the connect operation. socket_ops::connect(s, addr, addrlen, ec); @@ -503,8 +503,15 @@ void sync_connect(socket_type s, const socket_addr_type* addr, } // Wait for socket to become ready. - if (socket_ops::poll_connect(s, -1, ec) < 0) + int res = socket_ops::poll_connect(s, timeout_ms, ec); + if (res < 0) + return; + + if (res == 0) + { + ec = asio::error::timed_out; return; + } // Get the error code from the connect operation. int connect_error = 0; diff --git a/src/third_party/asio-master/asio/include/asio/detail/reactive_socket_service.hpp b/src/third_party/asio-master/asio/include/asio/detail/reactive_socket_service.hpp index b7b264806a9..ef9a9366a85 100644 --- a/src/third_party/asio-master/asio/include/asio/detail/reactive_socket_service.hpp +++ b/src/third_party/asio-master/asio/include/asio/detail/reactive_socket_service.hpp @@ -486,10 +486,10 @@ public: // Connect the socket to the specified endpoint. asio::error_code connect(implementation_type& impl, - const endpoint_type& peer_endpoint, asio::error_code& ec) + const endpoint_type& peer_endpoint, int timeout_ms, asio::error_code& ec) { socket_ops::sync_connect(impl.socket_, - peer_endpoint.data(), peer_endpoint.size(), ec); + peer_endpoint.data(), peer_endpoint.size(), timeout_ms, ec); return ec; } diff --git a/src/third_party/asio-master/asio/include/asio/detail/socket_ops.hpp b/src/third_party/asio-master/asio/include/asio/detail/socket_ops.hpp index b1fe32af429..2f2a1c38552 100644 --- a/src/third_party/asio-master/asio/include/asio/detail/socket_ops.hpp +++ b/src/third_party/asio-master/asio/include/asio/detail/socket_ops.hpp @@ -104,7 +104,7 @@ ASIO_DECL int connect(socket_type s, const socket_addr_type* addr, std::size_t addrlen, asio::error_code& ec); ASIO_DECL void sync_connect(socket_type s, const socket_addr_type* addr, - std::size_t addrlen, asio::error_code& ec); + std::size_t addrlen, int timeout_ms, asio::error_code& ec); #if defined(ASIO_HAS_IOCP) diff --git a/src/third_party/asio-master/asio/include/asio/detail/win_iocp_socket_service.hpp b/src/third_party/asio-master/asio/include/asio/detail/win_iocp_socket_service.hpp index ab099f6eab1..21d3f24fa77 100644 --- a/src/third_party/asio-master/asio/include/asio/detail/win_iocp_socket_service.hpp +++ b/src/third_party/asio-master/asio/include/asio/detail/win_iocp_socket_service.hpp @@ -562,10 +562,10 @@ public: // Connect the socket to the specified endpoint. asio::error_code connect(implementation_type& impl, - const endpoint_type& peer_endpoint, asio::error_code& ec) + const endpoint_type& peer_endpoint, int timeout_ms, asio::error_code& ec) { socket_ops::sync_connect(impl.socket_, - peer_endpoint.data(), peer_endpoint.size(), ec); + peer_endpoint.data(), peer_endpoint.size(), timeout_ms, ec); return ec; } |