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-2017 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_TRANSPORT_TCP_TRANSPORT_HPP
23 #define NDN_TRANSPORT_TCP_TRANSPORT_HPP
24 
25 #include "transport.hpp"
26 #include "../util/config-file.hpp"
27 
28 namespace boost {
29 namespace asio {
30 namespace ip {
31 class tcp;
32 } // namespace ip
33 } // namespace asio
34 } // namespace boost
35 
36 namespace ndn {
37 
38 template<typename BaseTransport, typename Protocol>
39 class StreamTransportImpl;
40 
41 template<typename BaseTransport, typename Protocol>
42 class StreamTransportWithResolverImpl;
43 
46 class TcpTransport : public Transport
47 {
48 public:
49  explicit
50  TcpTransport(const std::string& host, const std::string& port = "6363");
51 
52  ~TcpTransport() override;
53 
54  void
55  connect(boost::asio::io_service& ioService, const ReceiveCallback& receiveCallback) override;
56 
57  void
58  close() override;
59 
60  void
61  pause() override;
62 
63  void
64  resume() override;
65 
66  void
67  send(const Block& wire) override;
68 
69  void
70  send(const Block& header, const Block& payload) override;
71 
75  static shared_ptr<TcpTransport>
76  create(const std::string& uri);
77 
79  static std::pair<std::string, std::string>
80  getSocketHostAndPortFromUri(const std::string& uri);
81 
82 private:
83  std::string m_host;
84  std::string m_port;
85 
87  friend class StreamTransportImpl<TcpTransport, boost::asio::ip::tcp>;
88  friend Impl;
89  shared_ptr<Impl> m_impl;
90 };
91 
92 } // namespace ndn
93 
94 #endif // NDN_TRANSPORT_TCP_TRANSPORT_HPP
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
Copyright (c) 2013-2017 Regents of the University of California.
Definition: block.hpp:31
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:43
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
a transport using TCP socket
implementation detail of a Boost.Asio-based stream-oriented transport
implementation detail of a Boost.Asio-based stream-oriented transport with resolver support ...
provides TLV-block delivery service
Definition: transport.hpp:40
function< void(const Block &wire)> ReceiveCallback
Definition: transport.hpp:52