blob: 5fe14ee582338243a5d5b6b083c500bcc071061e [file] [log] [blame]
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080011 */
12
13#ifndef NDN_UDPTRANSPORT_HPP
14#define NDN_UDPTRANSPORT_HPP
15
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080016#include "../common.hpp"
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080017#include "transport.hpp"
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060018#include "../util/config-file.hpp"
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080019
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080020// forward declaration
21namespace boost { namespace asio { namespace local { class stream_protocol; } } }
22
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080023namespace ndn {
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080024
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080025// forward declaration
26template<class T, class U>
27class StreamTransportImpl;
28
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080029class UnixTransport : public Transport
30{
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080031public:
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080032
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060033 /**
34 * Create Unix transport based on the socket specified
35 * in a well-known configuration file or fallback to /var/run/nfd.sock
36 *
37 * @throws Throws UnixTransport::Error on failure to parse a discovered configuration file
38 */
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080039 UnixTransport(const std::string& unixSocket);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060040
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080041 ~UnixTransport();
42
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080043 // from Transport
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080044 virtual void
45 connect(boost::asio::io_service& ioService,
46 const ReceiveCallback& receiveCallback);
47
48 virtual void
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080049 close();
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080050
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080051 virtual void
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000052 pause();
53
54 virtual void
55 resume();
56
57 virtual void
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080058 send(const Block& wire);
59
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080060 virtual void
61 send(const Block& header, const Block& payload);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060062
63 /**
64 * Determine the default NFD unix socket
65 *
66 * @returns unix_socket value if present in config, else /var/run/nfd.sock
67 * @throws ConfigFile::Error if fail to parse value of a present "unix_socket" field
68 */
69 static std::string
70 getDefaultSocketName(const ConfigFile& config);
71
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080072private:
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080073 std::string m_unixSocket;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080074
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080075 typedef StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol> Impl;
76 friend class StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol>;
Alexander Afanasyevf73f0632014-05-12 18:02:37 -070077 shared_ptr< Impl > m_impl;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080078};
79
80}
81
82#endif