blob: 8afe007edc2c01c3b8bc56b3b59fa555a7a8c847 [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"
27
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080028// forward declaration
29namespace boost { namespace asio { namespace ip { class tcp; } } }
30
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080031namespace ndn {
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080032
33// forward declaration
34template<class T, class U> class StreamTransportImpl;
35template<class T, class U> class StreamTransportWithResolverImpl;
36
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080037class TcpTransport : public Transport
38{
39public:
40 TcpTransport(const std::string& host, const std::string& port = "6363");
41 ~TcpTransport();
42
43 // from Transport
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070044 virtual void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080045 connect(boost::asio::io_service& ioService,
46 const ReceiveCallback& receiveCallback);
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070047
48 virtual void
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080049 close();
50
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000051 virtual void
52 pause();
53
54 virtual void
55 resume();
56
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070057 virtual void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080058 send(const Block& wire);
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080059
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070060 virtual void
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080061 send(const Block& header, const Block& payload);
62
63private:
64 std::string m_host;
65 std::string m_port;
66
67 typedef StreamTransportWithResolverImpl<TcpTransport, boost::asio::ip::tcp> Impl;
68 friend class StreamTransportImpl<TcpTransport, boost::asio::ip::tcp>;
69 friend class StreamTransportWithResolverImpl<TcpTransport, boost::asio::ip::tcp>;
70 shared_ptr< Impl > m_impl;
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080071};
72
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080073} // namespace ndn
Alexander Afanasyev20d2c582014-01-26 15:32:51 -080074
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080075#endif // NDN_TRANSPORT_TCP_TRANSPORT_HPP