blob: 0ddd1a9f459986fbede2dd46cad97c594f744eb5 [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 Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070065 static shared_ptr<TcpTransport>
66 create(const ConfigFile& config);
67
68NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
69
70 static std::pair<std::string, std::string>
71 getDefaultSocketHostAndPort(const ConfigFile& config);
72
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080073private:
74 std::string m_host;
75 std::string m_port;
76
77 typedef StreamTransportWithResolverImpl<TcpTransport, boost::asio::ip::tcp> Impl;
78 friend class StreamTransportImpl<TcpTransport, boost::asio::ip::tcp>;
79 friend class StreamTransportWithResolverImpl<TcpTransport, boost::asio::ip::tcp>;
80 shared_ptr< Impl > m_impl;
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080081};
82
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080083} // namespace ndn
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080084
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080085#endif // NDN_TRANSPORT_TCP_TRANSPORT_HPP