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()) {
58 const FaceUri uri(uriString);
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"));
65 if (!uri.getHost().empty()) {
69 if (!uri.getPort().empty()) {
73 catch (
const FaceUri::Error& error) {
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);
113 if (m_impl !=
nullptr) {
122 BOOST_ASSERT(m_impl !=
nullptr);
Represents a TLV element of the NDN packet format.
a transport using TCP socket
TcpTransport(const std::string &host, const std::string &port="6363")
void send(const Block &wire) override
Send a TLV block through the transport.
void pause() override
Pause the transport, canceling all pending operations.
static shared_ptr< TcpTransport > create(const std::string &uri)
Create transport with parameters defined in URI.
void close() override
Close the connection.
void resume() override
Resume the transport.
void connect(boost::asio::io_service &ioService, ReceiveCallback receiveCallback) override
Asynchronously open the connection.
virtual void connect(boost::asio::io_service &ioService, ReceiveCallback receiveCallback)
Asynchronously open the connection.
std::function< void(const Block &wire)> ReceiveCallback
#define NDN_THROW_NESTED(e)
#define NDN_LOG_DEBUG(expression)
Log at DEBUG level.
#define NDN_LOG_INIT(name)
Define a non-member log module.