40 shared_ptr<TcpTransport>
44 return make_shared<TcpTransport>(hostAndPort.first, hostAndPort.second);
47 std::pair<std::string, std::string>
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 BOOST_THROW_EXCEPTION(
Error(
"Cannot create TcpTransport from \"" + scheme +
"\" URI"));
74 BOOST_THROW_EXCEPTION(
Error(error.what()));
84 NDN_LOG_DEBUG(
"connect host=" << m_host <<
" port=" << m_port);
86 if (m_impl ==
nullptr) {
89 m_impl = make_shared<Impl>(ref(*
this), ref(ioService));
92 boost::asio::ip::tcp::resolver::query query(m_host, m_port);
93 m_impl->connect(query);
99 BOOST_ASSERT(m_impl !=
nullptr);
106 BOOST_ASSERT(m_impl !=
nullptr);
107 m_impl->send(header, payload);
113 BOOST_ASSERT(m_impl !=
nullptr);
122 if (m_impl !=
nullptr) {
131 BOOST_ASSERT(m_impl !=
nullptr);
Copyright (c) 2011-2015 Regents of the University of California.
const std::string & getHost() const
get host (domain)
void resume() override
resume the transport
void connect(boost::asio::io_service &ioService, const ReceiveCallback &receiveCallback) override
asynchronously open the connection
const std::string & getPort() const
get port
Represents a TLV element of NDN packet format.
a transport using TCP socket
void send(const Block &wire) override
send a TLV block through the transport
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE std::string getSocketHostAndPortFromUri(const std::string &uri)
#define NDN_LOG_INIT(name)
declare a log module
#define NDN_LOG_DEBUG(expression)
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")
void pause() override
pause the transport
function< void(const Block &wire)> ReceiveCallback
virtual void connect(boost::asio::io_service &ioService, const ReceiveCallback &receiveCallback)
asynchronously open the connection