40 shared_ptr<TcpTransport>
43 const auto hostAndPort(getSocketHostAndPortFromUri(uri));
44 return make_shared<TcpTransport>(hostAndPort.first, hostAndPort.second);
47 std::pair<std::string, std::string>
48 TcpTransport::getSocketHostAndPortFromUri(
const std::string& uriString)
50 std::string host =
"localhost";
51 std::string port =
"6363";
53 if (uriString.empty()) {
60 const std::string scheme = uri.
getScheme();
61 if (scheme !=
"tcp" && scheme !=
"tcp4" && scheme !=
"tcp6") {
62 NDN_THROW(
Error(
"Cannot create TcpTransport from \"" + scheme +
"\" URI"));
83 NDN_LOG_DEBUG(
"connect host=" << m_host <<
" port=" << m_port);
85 if (m_impl ==
nullptr) {
87 m_impl = make_shared<Impl>(*
this, ioService);
90 boost::asio::ip::tcp::resolver::query query(m_host, m_port);
91 m_impl->connect(query);
97 BOOST_ASSERT(m_impl !=
nullptr);
104 BOOST_ASSERT(m_impl !=
nullptr);
105 m_impl->send(header, payload);
111 BOOST_ASSERT(m_impl !=
nullptr);
120 if (m_impl !=
nullptr) {
129 BOOST_ASSERT(m_impl !=
nullptr);
#define NDN_THROW_NESTED(e)
const std::string & getHost() const
get host (domain)
void resume() override
resume the transport
virtual void connect(boost::asio::io_service &ioService, ReceiveCallback receiveCallback)
Asynchronously open the connection.
const std::string & getPort() const
get port
Represents a TLV element of NDN packet format.
#define NDN_LOG_DEBUG(expression)
Log at DEBUG level.
#define NDN_LOG_INIT(name)
Define a non-member log module.
a transport using TCP socket
void send(const Block &wire) override
send a TLV block through the transport
void connect(boost::asio::io_service &ioService, ReceiveCallback receiveCallback) override
Asynchronously open the connection.
static shared_ptr< TcpTransport > create(const std::string &uri)
Create transport with parameters defined in URI.
represents the underlying protocol and address used by a Face
void close() override
Close the connection.
const std::string & getScheme() const
get scheme (protocol)
TcpTransport(const std::string &host, const std::string &port="6363")
std::function< void(const Block &wire)> ReceiveCallback
void pause() override
pause the transport