NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
unix-transport.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
#include "
unix-transport.hpp
"
23
#include "
stream-transport-impl.hpp
"
24
25
#include "../face.hpp"
26
#include "
util/face-uri.hpp
"
27
28
namespace
ndn
{
29
30
UnixTransport::UnixTransport
(
const
std::string& unixSocket)
31
: m_unixSocket(unixSocket)
32
{
33
}
34
35
UnixTransport::~UnixTransport
()
36
{
37
}
38
39
std::string
40
UnixTransport::getSocketNameFromUri(
const
std::string& uriString)
41
{
42
// Assume the default nfd.sock location.
43
std::string path =
"/var/run/nfd.sock"
;
44
45
if
(uriString.empty()) {
46
return
path;
47
}
48
49
try
{
50
const
util::FaceUri
uri(uriString);
51
52
if
(uri.
getScheme
() !=
"unix"
) {
53
BOOST_THROW_EXCEPTION(
Error
(
"Cannot create UnixTransport from \""
+
54
uri.
getScheme
() +
"\" URI"
));
55
}
56
57
if
(!uri.
getPath
().empty()) {
58
path = uri.
getPath
();
59
}
60
}
61
catch
(
const
util::FaceUri::Error
& error) {
62
BOOST_THROW_EXCEPTION(
Error
(error.what()));
63
}
64
65
return
path;
66
}
67
68
shared_ptr<UnixTransport>
69
UnixTransport::create
(
const
std::string& uri)
70
{
71
return
make_shared<UnixTransport>(getSocketNameFromUri(uri));
72
}
73
74
void
75
UnixTransport::connect
(boost::asio::io_service& ioService,
76
const
ReceiveCallback
& receiveCallback)
77
{
78
if
(m_impl ==
nullptr
) {
79
Transport::connect
(ioService, receiveCallback);
80
81
m_impl = make_shared<Impl>(ref(*
this
), ref(ioService));
82
}
83
84
m_impl->connect(boost::asio::local::stream_protocol::endpoint(m_unixSocket));
85
}
86
87
void
88
UnixTransport::send
(
const
Block
& wire)
89
{
90
BOOST_ASSERT(m_impl !=
nullptr
);
91
m_impl->send(wire);
92
}
93
94
void
95
UnixTransport::send
(
const
Block
& header,
const
Block
& payload)
96
{
97
BOOST_ASSERT(m_impl !=
nullptr
);
98
m_impl->send(header, payload);
99
}
100
101
void
102
UnixTransport::close
()
103
{
104
BOOST_ASSERT(m_impl !=
nullptr
);
105
m_impl->close();
106
m_impl.reset();
107
}
108
109
void
110
UnixTransport::pause
()
111
{
112
if
(m_impl !=
nullptr
) {
113
m_impl->pause();
114
}
115
}
116
117
void
118
UnixTransport::resume
()
119
{
120
BOOST_ASSERT(m_impl !=
nullptr
);
121
m_impl->resume();
122
}
123
124
}
// namespace ndn
ndn::Transport::Error
Definition:
transport.hpp:43
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::UnixTransport::~UnixTransport
~UnixTransport()
Definition:
unix-transport.cpp:35
ndn::util::FaceUri
represents the underlying protocol and address used by a Face
Definition:
face-uri.hpp:44
ndn::Block
Class representing a wire element of NDN-TLV packet format.
Definition:
block.hpp:43
unix-transport.hpp
ndn::UnixTransport::send
virtual void send(const Block &wire) override
send a TLV block through the transport
Definition:
unix-transport.cpp:88
ndn::util::FaceUri::getScheme
const std::string & getScheme() const
get scheme (protocol)
Definition:
face-uri.hpp:113
ndn::UnixTransport::create
static shared_ptr< UnixTransport > create(const std::string &uri)
Create transport with parameters defined in URI.
Definition:
unix-transport.cpp:69
ndn::UnixTransport::pause
virtual void pause() override
pause the transport
Definition:
unix-transport.cpp:110
ndn::UnixTransport::resume
virtual void resume() override
resume the transport
Definition:
unix-transport.cpp:118
ndn::UnixTransport::close
virtual void close() override
Close the connection.
Definition:
unix-transport.cpp:102
stream-transport-impl.hpp
ndn::util::FaceUri::Error
Definition:
face-uri.hpp:47
ndn::UnixTransport::connect
virtual void connect(boost::asio::io_service &ioService, const ReceiveCallback &receiveCallback) override
asynchronously open the connection
Definition:
unix-transport.cpp:75
ndn::UnixTransport::UnixTransport
UnixTransport(const std::string &unixSocket)
Definition:
unix-transport.cpp:30
face-uri.hpp
ndn::util::FaceUri::getPath
const std::string & getPath() const
get path
Definition:
face-uri.hpp:134
ndn::Transport::ReceiveCallback
function< void(const Block &wire)> ReceiveCallback
Definition:
transport.hpp:52
ndn::Transport::connect
virtual void connect(boost::asio::io_service &ioService, const ReceiveCallback &receiveCallback)
asynchronously open the connection
Definition:
transport.cpp:44
ndnSIM
ndn-cxx
src
transport
unix-transport.cpp
Generated on Wed Jan 11 2017 18:17:14 for ndnSIM by
1.8.13