41 shared_ptr<TcpTransport>
44 auto [host, port] = getSocketHostAndPortFromUri(uri);
45 return make_shared<TcpTransport>(host, port);
48 std::pair<std::string, std::string>
49 TcpTransport::getSocketHostAndPortFromUri(
const std::string& uriString)
52 std::string host =
"localhost";
53 std::string port =
"6363";
56 if (!uriString.empty()) {
60 const auto& 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()) {
68 if (!uri.getPort().empty()) {
72 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, ioCtx);
89 m_impl->connect(m_host, m_port);
95 BOOST_ASSERT(m_impl !=
nullptr);
102 BOOST_ASSERT(m_impl !=
nullptr);
111 if (m_impl !=
nullptr) {
120 BOOST_ASSERT(m_impl !=
nullptr);
Represents a TLV element of the NDN packet format.
The underlying protocol and address used by a Face.
A transport that uses a TCP socket for communication.
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 connect(boost::asio::io_context &ioCtx, ReceiveCallback receiveCallback) override
Asynchronously open the connection.
void close() override
Close the connection.
void resume() override
Resume the transport.
std::function< void(const Block &)> ReceiveCallback
virtual void connect(boost::asio::io_context &ioCtx, ReceiveCallback receiveCallback)
Asynchronously open the connection.
#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.