blob: 424ed539fb431573d7a27d6ce183dbe00f8136ae [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi020123a2017-08-08 14:33:48 +00002/*
Davide Pesavento19442812018-11-23 14:00:04 -05003 * Copyright (c) 2013-2018 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 Afanasyevfe3b1502013-12-18 16:45:03 -080020 */
21
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070022#ifndef NDN_TRANSPORT_UNIX_TRANSPORT_HPP
23#define NDN_TRANSPORT_UNIX_TRANSPORT_HPP
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080024
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "ndn-cxx/transport/transport.hpp"
26#include "ndn-cxx/util/config-file.hpp"
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080027
Davide Pesavento4d0d0962017-12-19 22:23:14 -050028#include <boost/asio/local/stream_protocol.hpp>
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080029
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080030namespace ndn {
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080031
Junxiao Shi70d76eb2018-12-18 13:15:43 -070032namespace detail {
33
Junxiao Shi446de3c2016-07-25 22:38:16 +000034template<typename BaseTransport, typename Protocol>
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080035class StreamTransportImpl;
36
Junxiao Shi70d76eb2018-12-18 13:15:43 -070037} // namespace detail
38
Junxiao Shi446de3c2016-07-25 22:38:16 +000039/** \brief a transport using Unix stream socket
40 */
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080041class UnixTransport : public Transport
42{
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080043public:
Junxiao Shi446de3c2016-07-25 22:38:16 +000044 explicit
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080045 UnixTransport(const std::string& unixSocket);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060046
Davide Pesavento57c07df2016-12-11 18:41:45 -050047 ~UnixTransport() override;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080048
Davide Pesavento57c07df2016-12-11 18:41:45 -050049 void
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080050 connect(boost::asio::io_service& ioService,
Junxiao Shi446de3c2016-07-25 22:38:16 +000051 const ReceiveCallback& receiveCallback) override;
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080052
Davide Pesavento57c07df2016-12-11 18:41:45 -050053 void
Junxiao Shi446de3c2016-07-25 22:38:16 +000054 close() override;
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080055
Davide Pesavento57c07df2016-12-11 18:41:45 -050056 void
Junxiao Shi446de3c2016-07-25 22:38:16 +000057 pause() override;
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000058
Davide Pesavento57c07df2016-12-11 18:41:45 -050059 void
Junxiao Shi446de3c2016-07-25 22:38:16 +000060 resume() override;
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000061
Davide Pesavento57c07df2016-12-11 18:41:45 -050062 void
Junxiao Shi446de3c2016-07-25 22:38:16 +000063 send(const Block& wire) override;
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080064
Davide Pesavento57c07df2016-12-11 18:41:45 -050065 void
Junxiao Shi446de3c2016-07-25 22:38:16 +000066 send(const Block& header, const Block& payload) override;
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060067
Junxiao Shi446de3c2016-07-25 22:38:16 +000068 /** \brief Create transport with parameters defined in URI
Junxiao Shi020123a2017-08-08 14:33:48 +000069 * \throw Transport::Error incorrect URI or unsupported protocol is specified
Alexander Afanasyev57e00362016-06-23 13:22:54 -070070 */
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070071 static shared_ptr<UnixTransport>
Alexander Afanasyev57e00362016-06-23 13:22:54 -070072 create(const std::string& uri);
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070073
74NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060075 static std::string
Alexander Afanasyev57e00362016-06-23 13:22:54 -070076 getSocketNameFromUri(const std::string& uri);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060077
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080078private:
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080079 std::string m_unixSocket;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080080
Junxiao Shi70d76eb2018-12-18 13:15:43 -070081 using Impl = detail::StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol>;
Junxiao Shi020123a2017-08-08 14:33:48 +000082 friend Impl;
Junxiao Shi446de3c2016-07-25 22:38:16 +000083 shared_ptr<Impl> m_impl;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080084};
85
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070086} // namespace ndn
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080087
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070088#endif // NDN_TRANSPORT_UNIX_TRANSPORT_HPP