blob: d3372521d19b34dccc0254ae29498f767c4ab8e8 [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/*
3 * Copyright (c) 2013-2017 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
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080025#include "transport.hpp"
Junxiao Shid27b0692014-12-28 10:33:14 -070026#include "../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 Shi446de3c2016-07-25 22:38:16 +000032template<typename BaseTransport, typename Protocol>
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080033class StreamTransportImpl;
34
Junxiao Shi446de3c2016-07-25 22:38:16 +000035/** \brief a transport using Unix stream socket
36 */
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080037class UnixTransport : public Transport
38{
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080039public:
Junxiao Shi446de3c2016-07-25 22:38:16 +000040 explicit
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080041 UnixTransport(const std::string& unixSocket);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060042
Davide Pesavento57c07df2016-12-11 18:41:45 -050043 ~UnixTransport() override;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080044
Davide Pesavento57c07df2016-12-11 18:41:45 -050045 void
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080046 connect(boost::asio::io_service& ioService,
Junxiao Shi446de3c2016-07-25 22:38:16 +000047 const ReceiveCallback& receiveCallback) override;
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080048
Davide Pesavento57c07df2016-12-11 18:41:45 -050049 void
Junxiao Shi446de3c2016-07-25 22:38:16 +000050 close() override;
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080051
Davide Pesavento57c07df2016-12-11 18:41:45 -050052 void
Junxiao Shi446de3c2016-07-25 22:38:16 +000053 pause() override;
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000054
Davide Pesavento57c07df2016-12-11 18:41:45 -050055 void
Junxiao Shi446de3c2016-07-25 22:38:16 +000056 resume() override;
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000057
Davide Pesavento57c07df2016-12-11 18:41:45 -050058 void
Junxiao Shi446de3c2016-07-25 22:38:16 +000059 send(const Block& wire) override;
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080060
Davide Pesavento57c07df2016-12-11 18:41:45 -050061 void
Junxiao Shi446de3c2016-07-25 22:38:16 +000062 send(const Block& header, const Block& payload) override;
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060063
Junxiao Shi446de3c2016-07-25 22:38:16 +000064 /** \brief Create transport with parameters defined in URI
Junxiao Shi020123a2017-08-08 14:33:48 +000065 * \throw Transport::Error incorrect URI or unsupported protocol is specified
Alexander Afanasyev57e00362016-06-23 13:22:54 -070066 */
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070067 static shared_ptr<UnixTransport>
Alexander Afanasyev57e00362016-06-23 13:22:54 -070068 create(const std::string& uri);
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070069
70NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060071 static std::string
Alexander Afanasyev57e00362016-06-23 13:22:54 -070072 getSocketNameFromUri(const std::string& uri);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060073
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080074private:
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080075 std::string m_unixSocket;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080076
Junxiao Shi020123a2017-08-08 14:33:48 +000077 using Impl = StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol>;
78 friend Impl;
Junxiao Shi446de3c2016-07-25 22:38:16 +000079 shared_ptr<Impl> m_impl;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080080};
81
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070082} // namespace ndn
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080083
Steve DiBenedettoa8659ff2014-12-04 14:50:28 -070084#endif // NDN_TRANSPORT_UNIX_TRANSPORT_HPP