blob: b0b51242378e5ef64cd5631fa65ca7d80a58899e [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev20d2c582014-01-26 15:32:51 -08002/**
Alexander Afanasyev57e00362016-06-23 13:22:54 -07003 * Copyright (c) 2013-2016 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080020 */
21
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080022#ifndef NDN_TRANSPORT_TCP_TRANSPORT_HPP
23#define NDN_TRANSPORT_TCP_TRANSPORT_HPP
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080024
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080025#include "../common.hpp"
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080026#include "transport.hpp"
Junxiao Shid27b0692014-12-28 10:33:14 -070027#include "../util/config-file.hpp"
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070028
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080029
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080030// forward declaration
31namespace boost { namespace asio { namespace ip { class tcp; } } }
32
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080033namespace ndn {
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080034
35// forward declaration
36template<class T, class U> class StreamTransportImpl;
37template<class T, class U> class StreamTransportWithResolverImpl;
38
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080039class TcpTransport : public Transport
40{
41public:
42 TcpTransport(const std::string& host, const std::string& port = "6363");
43 ~TcpTransport();
44
45 // from Transport
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070046 virtual void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080047 connect(boost::asio::io_service& ioService,
48 const ReceiveCallback& receiveCallback);
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070049
50 virtual void
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080051 close();
52
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000053 virtual void
54 pause();
55
56 virtual void
57 resume();
58
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070059 virtual void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080060 send(const Block& wire);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080061
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070062 virtual void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080063 send(const Block& header, const Block& payload);
64
Alexander Afanasyev57e00362016-06-23 13:22:54 -070065 /**
66 * @brief Create transport with parameters defined in URI
67 *
68 * @throws Transport::Error if incorrect URI or unsupported protocol is specified
69 */
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070070 static shared_ptr<TcpTransport>
Alexander Afanasyev57e00362016-06-23 13:22:54 -070071 create(const std::string& uri);
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070072
73NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
74
75 static std::pair<std::string, std::string>
Alexander Afanasyev57e00362016-06-23 13:22:54 -070076 getSocketHostAndPortFromUri(const std::string& uri);
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070077
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080078private:
79 std::string m_host;
80 std::string m_port;
81
82 typedef StreamTransportWithResolverImpl<TcpTransport, boost::asio::ip::tcp> Impl;
83 friend class StreamTransportImpl<TcpTransport, boost::asio::ip::tcp>;
84 friend class StreamTransportWithResolverImpl<TcpTransport, boost::asio::ip::tcp>;
85 shared_ptr< Impl > m_impl;
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080086};
87
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080088} // namespace ndn
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080089
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080090#endif // NDN_TRANSPORT_TCP_TRANSPORT_HPP