blob: f1e26ecbeed5499fac015bc8fd8446611f305d9d [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
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08007#include "common.hpp"
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -08008
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08009#include "unix-transport.hpp"
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080010#include "stream-transport.hpp"
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080011
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080012#include "../face.hpp"
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080013
14namespace ndn {
15
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080016UnixTransport::UnixTransport()
17{
18 if (std::getenv("NFD") != 0)
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080019 m_unixSocket = "/var/run/nfd.sock";
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080020 else
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080021 m_unixSocket = "/tmp/.ndnd.sock";
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080022}
23
24UnixTransport::UnixTransport(const std::string& unixSocket)
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080025 : m_unixSocket(unixSocket)
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080026{
27}
28
29UnixTransport::~UnixTransport()
30{
31}
32
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080033void
34UnixTransport::connect(boost::asio::io_service& ioService,
35 const ReceiveCallback& receiveCallback)
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080036{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080037 if (!static_cast<bool>(m_impl)) {
Alexander Afanasyev50ca6272014-01-09 23:23:54 -080038 Transport::connect(ioService, receiveCallback);
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080039
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080040 m_impl = make_shared<Impl> (boost::ref(*this),
41 boost::ref(ioService));
Alexander Afanasyev50ca6272014-01-09 23:23:54 -080042 }
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080043
44 m_impl->connect(boost::asio::local::stream_protocol::endpoint(m_unixSocket));
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080045}
46
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080047void
48UnixTransport::send(const Block& wire)
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080049{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080050 m_impl->send(wire);
51}
52
53void
54UnixTransport::send(const Block& header, const Block& payload)
55{
56 m_impl->send(header, payload);
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080057}
58
Alexander Afanasyevf7ca3202014-02-14 22:28:31 -080059void
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080060UnixTransport::close()
61{
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080062 m_impl->close();
Alexander Afanasyevfe3b1502013-12-18 16:45:03 -080063}
64
65}