tcp-transport.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2023 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_CXX_TRANSPORT_TCP_TRANSPORT_HPP
23 #define NDN_CXX_TRANSPORT_TCP_TRANSPORT_HPP
24 
26 
27 #include <boost/asio/ip/tcp.hpp>
28 
29 namespace ndn {
30 
31 namespace detail {
32 
33 template<typename BaseTransport, typename Protocol>
34 class StreamTransportImpl;
35 
36 template<typename BaseTransport, typename Protocol>
37 class StreamTransportWithResolverImpl;
38 
39 } // namespace detail
40 
44 class TcpTransport : public Transport
45 {
46 public:
47  explicit
48  TcpTransport(const std::string& host, const std::string& port = "6363");
49 
50  ~TcpTransport() override;
51 
52  void
53  connect(boost::asio::io_context& ioCtx, ReceiveCallback receiveCallback) override;
54 
55  void
56  close() override;
57 
58  void
59  pause() override;
60 
61  void
62  resume() override;
63 
64  void
65  send(const Block& wire) override;
66 
71  static shared_ptr<TcpTransport>
72  create(const std::string& uri);
73 
75  static std::pair<std::string, std::string>
76  getSocketHostAndPortFromUri(const std::string& uri);
77 
78 private:
79  std::string m_host;
80  std::string m_port;
81 
83  friend class detail::StreamTransportImpl<TcpTransport, boost::asio::ip::tcp>;
84  friend Impl;
85  shared_ptr<Impl> m_impl;
86 };
87 
88 } // namespace ndn
89 
90 #endif // NDN_CXX_TRANSPORT_TCP_TRANSPORT_HPP
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
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.
~TcpTransport() override
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.
Provides a "TLV-oriented" delivery service.
Definition: transport.hpp:37
std::function< void(const Block &)> ReceiveCallback
Definition: transport.hpp:54
Implementation detail of a Boost.Asio-based stream-oriented transport.
Implementation detail of a Boost.Asio-based stream-oriented transport with resolver support.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:49
Definition: data.cpp:25