Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 22 | #ifndef NDN_TRANSPORT_TCP_TRANSPORT_HPP |
| 23 | #define NDN_TRANSPORT_TCP_TRANSPORT_HPP |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 24 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 25 | #include "../common.hpp" |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 26 | #include "transport.hpp" |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame^] | 27 | #include "util/config-file.hpp" |
| 28 | |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 29 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 30 | // forward declaration |
| 31 | namespace boost { namespace asio { namespace ip { class tcp; } } } |
| 32 | |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 33 | namespace ndn { |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 34 | |
| 35 | // forward declaration |
| 36 | template<class T, class U> class StreamTransportImpl; |
| 37 | template<class T, class U> class StreamTransportWithResolverImpl; |
| 38 | |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 39 | class TcpTransport : public Transport |
| 40 | { |
| 41 | public: |
| 42 | TcpTransport(const std::string& host, const std::string& port = "6363"); |
| 43 | ~TcpTransport(); |
| 44 | |
| 45 | // from Transport |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 46 | virtual void |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 47 | connect(boost::asio::io_service& ioService, |
| 48 | const ReceiveCallback& receiveCallback); |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 49 | |
| 50 | virtual void |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 51 | close(); |
| 52 | |
Alexander Afanasyev | 52afb3f | 2014-03-07 09:05:35 +0000 | [diff] [blame] | 53 | virtual void |
| 54 | pause(); |
| 55 | |
| 56 | virtual void |
| 57 | resume(); |
| 58 | |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 59 | virtual void |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 60 | send(const Block& wire); |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 61 | |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 62 | virtual void |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 63 | send(const Block& header, const Block& payload); |
| 64 | |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame^] | 65 | static shared_ptr<TcpTransport> |
| 66 | create(const ConfigFile& config); |
| 67 | |
| 68 | NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 69 | |
| 70 | static std::pair<std::string, std::string> |
| 71 | getDefaultSocketHostAndPort(const ConfigFile& config); |
| 72 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 73 | private: |
| 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 Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 81 | }; |
| 82 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 83 | } // namespace ndn |
Alexander Afanasyev | 20d2c58 | 2014-01-26 15:32:51 -0800 | [diff] [blame] | 84 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 85 | #endif // NDN_TRANSPORT_TCP_TRANSPORT_HPP |