Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 3 | * Copyright (C) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NDN_UDPTRANSPORT_HPP |
| 8 | #define NDN_UDPTRANSPORT_HPP |
| 9 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 10 | #include "../common.hpp" |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 11 | #include "transport.hpp" |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame^] | 12 | #include "../util/config-file.hpp" |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 13 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 14 | // forward declaration |
| 15 | namespace boost { namespace asio { namespace local { class stream_protocol; } } } |
| 16 | |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 17 | namespace ndn { |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 18 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 19 | // forward declaration |
| 20 | template<class T, class U> |
| 21 | class StreamTransportImpl; |
| 22 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 23 | class UnixTransport : public Transport |
| 24 | { |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 25 | public: |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 26 | |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame^] | 27 | /** |
| 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 Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 33 | UnixTransport(const std::string& unixSocket); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame^] | 34 | |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 35 | ~UnixTransport(); |
| 36 | |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 37 | // from Transport |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 38 | virtual void |
| 39 | connect(boost::asio::io_service& ioService, |
| 40 | const ReceiveCallback& receiveCallback); |
| 41 | |
| 42 | virtual void |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 43 | close(); |
Alexander Afanasyev | e2e0d75 | 2014-01-03 13:30:30 -0800 | [diff] [blame] | 44 | |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 45 | virtual void |
Alexander Afanasyev | 52afb3f | 2014-03-07 09:05:35 +0000 | [diff] [blame] | 46 | pause(); |
| 47 | |
| 48 | virtual void |
| 49 | resume(); |
| 50 | |
| 51 | virtual void |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 52 | send(const Block& wire); |
| 53 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 54 | virtual void |
| 55 | send(const Block& header, const Block& payload); |
Steve DiBenedetto | c07b3a2 | 2014-03-19 12:32:52 -0600 | [diff] [blame^] | 56 | |
| 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 Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 66 | private: |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 67 | std::string m_unixSocket; |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 68 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 69 | 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 Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | } |
| 75 | |
| 76 | #endif |