blob: 47636fac1e67cfd427f5256a3d46440a6da0276f [file] [log] [blame]
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyev5964fb72014-02-18 12:42:45 -08003 * Copyright (C) 2013-2014 Regents of the University of California.
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -08004 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NDN_UDPTRANSPORT_HPP
8#define NDN_UDPTRANSPORT_HPP
9
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080010#include "../common.hpp"
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080011#include "transport.hpp"
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060012#include "../util/config-file.hpp"
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080013
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080014// forward declaration
15namespace boost { namespace asio { namespace local { class stream_protocol; } } }
16
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080017namespace ndn {
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080018
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080019// forward declaration
20template<class T, class U>
21class StreamTransportImpl;
22
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080023class UnixTransport : public Transport
24{
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080025public:
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080026
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060027 /**
28 * Create Unix transport based on the socket specified
29 * in a well-known configuration file or fallback to /var/run/nfd.sock
30 *
31 * @throws Throws UnixTransport::Error on failure to parse a discovered configuration file
32 */
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080033 UnixTransport(const std::string& unixSocket);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060034
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080035 ~UnixTransport();
36
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080037 // from Transport
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080038 virtual void
39 connect(boost::asio::io_service& ioService,
40 const ReceiveCallback& receiveCallback);
41
42 virtual void
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080043 close();
Alexander Afanasyeve2e0d752014-01-03 13:30:30 -080044
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080045 virtual void
Alexander Afanasyev52afb3f2014-03-07 09:05:35 +000046 pause();
47
48 virtual void
49 resume();
50
51 virtual void
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080052 send(const Block& wire);
53
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080054 virtual void
55 send(const Block& header, const Block& payload);
Steve DiBenedettoc07b3a22014-03-19 12:32:52 -060056
57 /**
58 * Determine the default NFD unix socket
59 *
60 * @returns unix_socket value if present in config, else /var/run/nfd.sock
61 * @throws ConfigFile::Error if fail to parse value of a present "unix_socket" field
62 */
63 static std::string
64 getDefaultSocketName(const ConfigFile& config);
65
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080066private:
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080067 std::string m_unixSocket;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080068
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080069 typedef StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol> Impl;
70 friend class StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol>;
71 ptr_lib::shared_ptr< Impl > m_impl;
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080072};
73
74}
75
76#endif