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 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 7 | #include "common.hpp" |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 8 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 9 | #include "unix-transport.hpp" |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 10 | #include "stream-transport.hpp" |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 11 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 12 | #include "../face.hpp" |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 13 | |
| 14 | namespace ndn { |
| 15 | |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 16 | UnixTransport::UnixTransport() |
| 17 | { |
| 18 | if (std::getenv("NFD") != 0) |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 19 | m_unixSocket = "/var/run/nfd.sock"; |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 20 | else |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 21 | m_unixSocket = "/tmp/.ndnd.sock"; |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | UnixTransport::UnixTransport(const std::string& unixSocket) |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 25 | : m_unixSocket(unixSocket) |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 26 | { |
| 27 | } |
| 28 | |
| 29 | UnixTransport::~UnixTransport() |
| 30 | { |
| 31 | } |
| 32 | |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 33 | void |
| 34 | UnixTransport::connect(boost::asio::io_service& ioService, |
| 35 | const ReceiveCallback& receiveCallback) |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 36 | { |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 37 | if (!static_cast<bool>(m_impl)) { |
Alexander Afanasyev | 50ca627 | 2014-01-09 23:23:54 -0800 | [diff] [blame] | 38 | Transport::connect(ioService, receiveCallback); |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 39 | |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 40 | m_impl = make_shared<Impl> (boost::ref(*this), |
| 41 | boost::ref(ioService)); |
Alexander Afanasyev | 50ca627 | 2014-01-09 23:23:54 -0800 | [diff] [blame] | 42 | } |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 43 | |
| 44 | m_impl->connect(boost::asio::local::stream_protocol::endpoint(m_unixSocket)); |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 47 | void |
| 48 | UnixTransport::send(const Block& wire) |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 49 | { |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 50 | m_impl->send(wire); |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | UnixTransport::send(const Block& header, const Block& payload) |
| 55 | { |
| 56 | m_impl->send(header, payload); |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Alexander Afanasyev | f7ca320 | 2014-02-14 22:28:31 -0800 | [diff] [blame] | 59 | void |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 60 | UnixTransport::close() |
| 61 | { |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 62 | m_impl->close(); |
Alexander Afanasyev | fe3b150 | 2013-12-18 16:45:03 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | } |