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 | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 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 | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 22 | #ifndef NDN_TRANSPORT_UNIX_TRANSPORT_HPP |
| 23 | #define NDN_TRANSPORT_UNIX_TRANSPORT_HPP |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 24 | |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 25 | #include "transport.hpp" |
Junxiao Shi | d27b069 | 2014-12-28 10:33:14 -0700 | [diff] [blame] | 26 | #include "../util/config-file.hpp" |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 27 | |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame] | 28 | namespace boost { |
| 29 | namespace asio { |
| 30 | namespace local { |
| 31 | class stream_protocol; |
| 32 | } // namespace local |
| 33 | } // namespace asio |
| 34 | } // namespace boost |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 35 | |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 36 | namespace ndn { |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 37 | |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame] | 38 | template<typename BaseTransport, typename Protocol> |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 39 | class StreamTransportImpl; |
| 40 | |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame] | 41 | /** \brief a transport using Unix stream socket |
| 42 | */ |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 43 | class UnixTransport : public Transport |
| 44 | { |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 45 | public: |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame] | 46 | explicit |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 47 | UnixTransport(const std::string& unixSocket); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 48 | |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 49 | ~UnixTransport(); |
| 50 | |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 51 | virtual void |
| 52 | connect(boost::asio::io_service& ioService, |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame] | 53 | const ReceiveCallback& receiveCallback) override; |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 54 | |
| 55 | virtual void |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame] | 56 | close() override; |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 57 | |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 58 | virtual void |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame] | 59 | pause() override; |
Alexander Afanasyev | 52afb3f | 2014-03-07 09:05:35 +0000 | [diff] [blame] | 60 | |
| 61 | virtual void |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame] | 62 | resume() override; |
Alexander Afanasyev | 52afb3f | 2014-03-07 09:05:35 +0000 | [diff] [blame] | 63 | |
| 64 | virtual void |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame] | 65 | send(const Block& wire) override; |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 66 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 67 | virtual void |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame] | 68 | send(const Block& header, const Block& payload) override; |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 69 | |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame] | 70 | /** \brief Create transport with parameters defined in URI |
| 71 | * \throw Transport::Error if incorrect URI or unsupported protocol is specified |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 72 | */ |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 73 | static shared_ptr<UnixTransport> |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 74 | create(const std::string& uri); |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 75 | |
| 76 | NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 77 | static std::string |
Alexander Afanasyev | 57e0036 | 2016-06-23 13:22:54 -0700 | [diff] [blame] | 78 | getSocketNameFromUri(const std::string& uri); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame] | 79 | |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 80 | private: |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 81 | std::string m_unixSocket; |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 82 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 83 | typedef StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol> Impl; |
| 84 | friend class StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol>; |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame] | 85 | shared_ptr<Impl> m_impl; |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 88 | } // namespace ndn |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 89 | |
Steve DiBenedetto | a8659ff | 2014-12-04 14:50:28 -0700 | [diff] [blame] | 90 | #endif // NDN_TRANSPORT_UNIX_TRANSPORT_HPP |