acceptor_callback_(ec);
if (!ec) {
- if (connection_filter_) {
- // In theory, we should not get here with an unopened socket
- // but just in case, we'll check for NO_ENDPOINT.
- auto endpoint = getRemoteEndpoint();
- if (endpoint == NO_ENDPOINT() || !connection_filter_(endpoint)) {
- LOG_DEBUG(tcp_logger, isc::log::DBGLVL_TRACE_DETAIL,
- TCP_CONNECTION_REJECTED_BY_FILTER)
- .arg(getRemoteEndpointAddressAsText());
- stopThisConnection();
- TcpConnectionPool::rejected_counter_ += 1;
- return;
+ try {
+ if (tcp_socket_ && tcp_socket_->getASIOSocket().is_open()) {
+ remote_endpoint_ =
+ tcp_socket_->getASIOSocket().remote_endpoint();
+ } else if (tls_socket_ && tls_socket_->getASIOSocket().is_open()) {
+ remote_endpoint_ =
+ tls_socket_->getASIOSocket().remote_endpoint();
}
+ } catch (...) {
+ // Let's it to fail later.
+ }
+
+ // In theory, we should not get here with an unopened socket
+ // but just in case, we'll check for NO_ENDPOINT.
+ if ((remote_endpoint_ == NO_ENDPOINT()) ||
+ (connection_filter_ && !connection_filter_(remote_endpoint_))) {
+ LOG_DEBUG(tcp_logger, isc::log::DBGLVL_TRACE_DETAIL,
+ TCP_CONNECTION_REJECTED_BY_FILTER)
+ .arg(getRemoteEndpointAddressAsText());
+ TcpConnectionPool::rejected_counter_ += 1;
+ stopThisConnection();
+ return;
}
if (!tls_context_) {
stopThisConnection();
}
-const boost::asio::ip::tcp::endpoint
-TcpConnection::getRemoteEndpoint() const {
- try {
- if (tcp_socket_) {
- if (tcp_socket_->getASIOSocket().is_open()) {
- return (tcp_socket_->getASIOSocket().remote_endpoint());
- }
- } else if (tls_socket_) {
- if (tls_socket_->getASIOSocket().is_open()) {
- return (tls_socket_->getASIOSocket().remote_endpoint());
- }
- }
- } catch (...) {
- }
-
- return (NO_ENDPOINT());
-}
-
std::string
TcpConnection::getRemoteEndpointAddressAsText() const {
-
- auto endpoint = getRemoteEndpoint();
- if (endpoint != NO_ENDPOINT()) {
- return (endpoint.address().to_string());
+ if (remote_endpoint_ != NO_ENDPOINT()) {
+ return (remote_endpoint_.address().to_string());
}
return ("(unknown address)");
///
/// @return A reference to the endpoint if the socket is open, otherwise
/// NO_ENDPOINT.
- const boost::asio::ip::tcp::endpoint getRemoteEndpoint() const;
+ const boost::asio::ip::tcp::endpoint getRemoteEndpoint() const {
+ return (remote_endpoint_);
+ }
protected:
/// @brief Buffer for a single socket read.
WireData input_buf_;
+
+ /// @brief Remote endpoint.
+ boost::asio::ip::tcp::endpoint remote_endpoint_;
};
/// @brief Pointer to the @ref TcpConnection.