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