Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014 Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology |
| 9 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 24 | |
| 25 | #include "tcp-channel.hpp" |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 26 | #include "core/global-io.hpp" |
| 27 | #include "core/face-uri.hpp" |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 29 | namespace nfd { |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | 3958b01 | 2014-01-31 15:06:13 -0800 | [diff] [blame] | 31 | NFD_LOG_INIT("TcpChannel"); |
| 32 | |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 33 | using namespace boost::asio; |
| 34 | |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 35 | TcpChannel::TcpChannel(const tcp::Endpoint& localEndpoint) |
| 36 | : m_localEndpoint(localEndpoint) |
Alexander Afanasyev | 53a6fd3 | 2014-03-23 00:00:04 -0700 | [diff] [blame] | 37 | , m_isListening(false) |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 38 | { |
| 39 | this->setUri(FaceUri(localEndpoint)); |
| 40 | } |
| 41 | |
| 42 | TcpChannel::~TcpChannel() |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
| 46 | void |
Alexander Afanasyev | 855a53c | 2014-01-27 12:03:00 -0800 | [diff] [blame] | 47 | TcpChannel::listen(const FaceCreatedCallback& onFaceCreated, |
| 48 | const ConnectFailedCallback& onAcceptFailed, |
| 49 | int backlog/* = tcp::acceptor::max_connections*/) |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 50 | { |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 51 | m_acceptor = make_shared<ip::tcp::acceptor>(boost::ref(getGlobalIoService())); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 52 | m_acceptor->open(m_localEndpoint.protocol()); |
| 53 | m_acceptor->set_option(ip::tcp::acceptor::reuse_address(true)); |
Alexander Afanasyev | eee71fd | 2014-03-13 17:40:33 -0700 | [diff] [blame] | 54 | if (m_localEndpoint.address().is_v6()) |
| 55 | { |
| 56 | m_acceptor->set_option(ip::v6_only(true)); |
| 57 | } |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 58 | m_acceptor->bind(m_localEndpoint); |
| 59 | m_acceptor->listen(backlog); |
| 60 | |
| 61 | shared_ptr<ip::tcp::socket> clientSocket = |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 62 | make_shared<ip::tcp::socket>(boost::ref(getGlobalIoService())); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 63 | m_acceptor->async_accept(*clientSocket, |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 64 | bind(&TcpChannel::handleSuccessfulAccept, this, _1, |
Alexander Afanasyev | 855a53c | 2014-01-27 12:03:00 -0800 | [diff] [blame] | 65 | clientSocket, |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 66 | onFaceCreated, onAcceptFailed)); |
Alexander Afanasyev | 53a6fd3 | 2014-03-23 00:00:04 -0700 | [diff] [blame] | 67 | |
| 68 | m_isListening = true; |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 72 | TcpChannel::connect(const tcp::Endpoint& remoteEndpoint, |
Alexander Afanasyev | 855a53c | 2014-01-27 12:03:00 -0800 | [diff] [blame] | 73 | const TcpChannel::FaceCreatedCallback& onFaceCreated, |
| 74 | const TcpChannel::ConnectFailedCallback& onConnectFailed, |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 75 | const time::seconds& timeout/* = time::seconds(4)*/) |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 76 | { |
Alexander Afanasyev | 334b714 | 2014-01-28 12:59:39 -0800 | [diff] [blame] | 77 | ChannelFaceMap::iterator i = m_channelFaces.find(remoteEndpoint); |
| 78 | if (i != m_channelFaces.end()) { |
| 79 | onFaceCreated(i->second); |
| 80 | return; |
| 81 | } |
| 82 | |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 83 | shared_ptr<ip::tcp::socket> clientSocket = |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 84 | make_shared<ip::tcp::socket>(boost::ref(getGlobalIoService())); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 85 | |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 86 | shared_ptr<ndn::monotonic_deadline_timer> connectTimeoutTimer = |
| 87 | make_shared<ndn::monotonic_deadline_timer>(boost::ref(getGlobalIoService())); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 88 | |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 89 | clientSocket->async_connect(remoteEndpoint, |
Alexander Afanasyev | 855a53c | 2014-01-27 12:03:00 -0800 | [diff] [blame] | 90 | bind(&TcpChannel::handleSuccessfulConnect, this, _1, |
| 91 | clientSocket, connectTimeoutTimer, |
| 92 | onFaceCreated, onConnectFailed)); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 93 | |
| 94 | connectTimeoutTimer->expires_from_now(timeout); |
Alexander Afanasyev | 855a53c | 2014-01-27 12:03:00 -0800 | [diff] [blame] | 95 | connectTimeoutTimer->async_wait(bind(&TcpChannel::handleFailedConnect, this, _1, |
| 96 | clientSocket, connectTimeoutTimer, |
| 97 | onConnectFailed)); |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 100 | void |
| 101 | TcpChannel::connect(const std::string& remoteHost, const std::string& remotePort, |
Alexander Afanasyev | 855a53c | 2014-01-27 12:03:00 -0800 | [diff] [blame] | 102 | const TcpChannel::FaceCreatedCallback& onFaceCreated, |
| 103 | const TcpChannel::ConnectFailedCallback& onConnectFailed, |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 104 | const time::seconds& timeout/* = time::seconds(4)*/) |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 105 | { |
| 106 | shared_ptr<ip::tcp::socket> clientSocket = |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 107 | make_shared<ip::tcp::socket>(boost::ref(getGlobalIoService())); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 108 | |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 109 | shared_ptr<ndn::monotonic_deadline_timer> connectTimeoutTimer = |
| 110 | make_shared<ndn::monotonic_deadline_timer>(boost::ref(getGlobalIoService())); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 111 | |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 112 | ip::tcp::resolver::query query(remoteHost, remotePort); |
| 113 | shared_ptr<ip::tcp::resolver> resolver = |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 114 | make_shared<ip::tcp::resolver>(boost::ref(getGlobalIoService())); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 115 | |
| 116 | resolver->async_resolve(query, |
Davide Pesavento | 855bf29 | 2014-02-27 03:58:01 +0100 | [diff] [blame] | 117 | bind(&TcpChannel::handleEndpointResolution, this, _1, _2, |
Alexander Afanasyev | 855a53c | 2014-01-27 12:03:00 -0800 | [diff] [blame] | 118 | clientSocket, connectTimeoutTimer, |
Alexander Afanasyev | 3958b01 | 2014-01-31 15:06:13 -0800 | [diff] [blame] | 119 | onFaceCreated, onConnectFailed, |
| 120 | resolver)); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 121 | |
| 122 | connectTimeoutTimer->expires_from_now(timeout); |
Alexander Afanasyev | 855a53c | 2014-01-27 12:03:00 -0800 | [diff] [blame] | 123 | connectTimeoutTimer->async_wait(bind(&TcpChannel::handleFailedConnect, this, _1, |
| 124 | clientSocket, connectTimeoutTimer, |
| 125 | onConnectFailed)); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 128 | size_t |
| 129 | TcpChannel::size() const |
| 130 | { |
| 131 | return m_channelFaces.size(); |
| 132 | } |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 133 | |
| 134 | void |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 135 | TcpChannel::createFace(const shared_ptr<ip::tcp::socket>& socket, |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 136 | const FaceCreatedCallback& onFaceCreated, |
| 137 | bool isOnDemand) |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 138 | { |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 139 | tcp::Endpoint remoteEndpoint = socket->remote_endpoint(); |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 140 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 141 | shared_ptr<Face> face; |
Alexander Afanasyev | bfd31de | 2014-02-26 13:20:08 -0800 | [diff] [blame] | 142 | if (socket->local_endpoint().address().is_loopback()) |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 143 | face = make_shared<TcpLocalFace>(boost::cref(socket), isOnDemand); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 144 | else |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 145 | face = make_shared<TcpFace>(boost::cref(socket), isOnDemand); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 146 | |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 147 | face->onFail += bind(&TcpChannel::afterFaceFailed, this, remoteEndpoint); |
| 148 | |
| 149 | onFaceCreated(face); |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 150 | m_channelFaces[remoteEndpoint] = face; |
| 151 | } |
| 152 | |
| 153 | void |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 154 | TcpChannel::afterFaceFailed(tcp::Endpoint &remoteEndpoint) |
| 155 | { |
| 156 | NFD_LOG_DEBUG("afterFaceFailed: " << remoteEndpoint); |
| 157 | m_channelFaces.erase(remoteEndpoint); |
| 158 | } |
| 159 | |
| 160 | void |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 161 | TcpChannel::handleSuccessfulAccept(const boost::system::error_code& error, |
| 162 | const shared_ptr<boost::asio::ip::tcp::socket>& socket, |
| 163 | const FaceCreatedCallback& onFaceCreated, |
| 164 | const ConnectFailedCallback& onAcceptFailed) |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 165 | { |
| 166 | if (error) { |
| 167 | if (error == boost::system::errc::operation_canceled) // when socket is closed by someone |
| 168 | return; |
| 169 | |
Alexander Afanasyev | 3958b01 | 2014-01-31 15:06:13 -0800 | [diff] [blame] | 170 | NFD_LOG_DEBUG("Connect to remote endpoint failed: " |
| 171 | << error.category().message(error.value())); |
Alexander Afanasyev | 5f1ec25 | 2014-02-28 10:59:17 -0800 | [diff] [blame] | 172 | |
| 173 | if (static_cast<bool>(onAcceptFailed)) |
| 174 | onAcceptFailed("Connect to remote endpoint failed: " + |
| 175 | error.category().message(error.value())); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 176 | return; |
| 177 | } |
| 178 | |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 179 | // prepare accepting the next connection |
| 180 | shared_ptr<ip::tcp::socket> clientSocket = |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 181 | make_shared<ip::tcp::socket>(boost::ref(getGlobalIoService())); |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 182 | m_acceptor->async_accept(*clientSocket, |
| 183 | bind(&TcpChannel::handleSuccessfulAccept, this, _1, |
| 184 | clientSocket, |
| 185 | onFaceCreated, onAcceptFailed)); |
Alexander Afanasyev | 334b714 | 2014-01-28 12:59:39 -0800 | [diff] [blame] | 186 | |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 187 | NFD_LOG_DEBUG("[" << m_localEndpoint << "] " |
| 188 | "<< Connection from " << socket->remote_endpoint()); |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 189 | createFace(socket, onFaceCreated, true); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void |
| 193 | TcpChannel::handleSuccessfulConnect(const boost::system::error_code& error, |
| 194 | const shared_ptr<ip::tcp::socket>& socket, |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 195 | const shared_ptr<ndn::monotonic_deadline_timer>& timer, |
Alexander Afanasyev | 855a53c | 2014-01-27 12:03:00 -0800 | [diff] [blame] | 196 | const FaceCreatedCallback& onFaceCreated, |
| 197 | const ConnectFailedCallback& onConnectFailed) |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 198 | { |
| 199 | timer->cancel(); |
| 200 | |
| 201 | if (error) { |
| 202 | if (error == boost::system::errc::operation_canceled) // when socket is closed by someone |
| 203 | return; |
| 204 | |
| 205 | socket->close(); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 206 | |
Alexander Afanasyev | 3958b01 | 2014-01-31 15:06:13 -0800 | [diff] [blame] | 207 | NFD_LOG_DEBUG("Connect to remote endpoint failed: " |
| 208 | << error.category().message(error.value())); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 209 | |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 210 | onConnectFailed("Connect to remote endpoint failed: " + |
| 211 | error.category().message(error.value())); |
| 212 | return; |
| 213 | } |
| 214 | |
Alexander Afanasyev | a16abd2 | 2014-01-31 18:12:29 -0800 | [diff] [blame] | 215 | NFD_LOG_DEBUG("[" << m_localEndpoint << "] " |
| 216 | ">> Connection to " << socket->remote_endpoint()); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 217 | |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 218 | createFace(socket, onFaceCreated, false); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void |
| 222 | TcpChannel::handleFailedConnect(const boost::system::error_code& error, |
| 223 | const shared_ptr<ip::tcp::socket>& socket, |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 224 | const shared_ptr<ndn::monotonic_deadline_timer>& timer, |
Alexander Afanasyev | 855a53c | 2014-01-27 12:03:00 -0800 | [diff] [blame] | 225 | const ConnectFailedCallback& onConnectFailed) |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 226 | { |
| 227 | if (error) { // e.g., cancelled |
| 228 | return; |
| 229 | } |
| 230 | |
Alexander Afanasyev | 3958b01 | 2014-01-31 15:06:13 -0800 | [diff] [blame] | 231 | NFD_LOG_DEBUG("Connect to remote endpoint timed out: " |
| 232 | << error.category().message(error.value())); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 233 | |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 234 | onConnectFailed("Connect to remote endpoint timed out: " + |
| 235 | error.category().message(error.value())); |
| 236 | socket->close(); // abort the connection |
| 237 | } |
| 238 | |
| 239 | void |
Davide Pesavento | 855bf29 | 2014-02-27 03:58:01 +0100 | [diff] [blame] | 240 | TcpChannel::handleEndpointResolution(const boost::system::error_code& error, |
| 241 | ip::tcp::resolver::iterator remoteEndpoint, |
| 242 | const shared_ptr<boost::asio::ip::tcp::socket>& socket, |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 243 | const shared_ptr<ndn::monotonic_deadline_timer>& timer, |
Davide Pesavento | 855bf29 | 2014-02-27 03:58:01 +0100 | [diff] [blame] | 244 | const FaceCreatedCallback& onFaceCreated, |
| 245 | const ConnectFailedCallback& onConnectFailed, |
| 246 | const shared_ptr<ip::tcp::resolver>& resolver) |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 247 | { |
| 248 | if (error || |
| 249 | remoteEndpoint == ip::tcp::resolver::iterator()) |
| 250 | { |
| 251 | if (error == boost::system::errc::operation_canceled) // when socket is closed by someone |
| 252 | return; |
| 253 | |
| 254 | socket->close(); |
| 255 | timer->cancel(); |
Alexander Afanasyev | 3958b01 | 2014-01-31 15:06:13 -0800 | [diff] [blame] | 256 | |
| 257 | NFD_LOG_DEBUG("Remote endpoint hostname or port cannot be resolved: " |
| 258 | << error.category().message(error.value())); |
Junxiao Shi | 61e3cc5 | 2014-03-03 20:40:28 -0700 | [diff] [blame] | 259 | |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 260 | onConnectFailed("Remote endpoint hostname or port cannot be resolved: " + |
| 261 | error.category().message(error.value())); |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | // got endpoint, now trying to connect (only try the first resolution option) |
| 266 | socket->async_connect(*remoteEndpoint, |
Alexander Afanasyev | 855a53c | 2014-01-27 12:03:00 -0800 | [diff] [blame] | 267 | bind(&TcpChannel::handleSuccessfulConnect, this, _1, |
| 268 | socket, timer, |
| 269 | onFaceCreated, onConnectFailed)); |
Alexander Afanasyev | 8ad71ba | 2014-01-27 00:07:14 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 272 | } // namespace nfd |