31 #include <boost/filesystem.hpp> 40 bool wantCongestionMarking)
41 : m_endpoint(endpoint)
45 , m_wantCongestionMarking(wantCongestionMarking)
56 boost::system::error_code error;
57 m_acceptor.close(error);
59 boost::filesystem::remove(m_endpoint.path(), error);
73 namespace fs = boost::filesystem;
75 fs::path socketPath(m_endpoint.path());
76 fs::file_type type = fs::symlink_status(socketPath).type();
78 if (type == fs::socket_file) {
79 boost::system::error_code error;
81 socket.connect(m_endpoint, error);
85 BOOST_THROW_EXCEPTION(
Error(
"Socket file at " + m_endpoint.path()
86 +
" belongs to another NFD process"));
88 else if (error == boost::asio::error::connection_refused ||
89 error == boost::asio::error::timed_out) {
93 fs::remove(socketPath);
96 else if (type != fs::file_not_found) {
97 BOOST_THROW_EXCEPTION(
Error(m_endpoint.path() +
" already exists and is not a socket file"));
101 m_acceptor.bind(m_endpoint);
102 m_acceptor.listen(backlog);
104 if (::chmod(m_endpoint.path().data(), 0666) < 0) {
105 BOOST_THROW_EXCEPTION(
Error(
"chmod(" + m_endpoint.path() +
") failed: " + std::strerror(errno)));
108 accept(onFaceCreated, onAcceptFailed);
116 m_acceptor.async_accept(m_socket, [=] (
const auto& e) { this->handleAccept(e, onFaceCreated, onAcceptFailed); });
120 UnixStreamChannel::handleAccept(
const boost::system::error_code& error,
125 if (error != boost::asio::error::operation_aborted) {
128 onAcceptFailed(500,
"Accept failed: " + error.message());
135 GenericLinkService::Options options;
136 options.allowCongestionMarking = m_wantCongestionMarking;
137 auto linkService = make_unique<GenericLinkService>(options);
138 auto transport = make_unique<UnixStreamTransport>(std::move(m_socket));
139 auto face = make_shared<Face>(std::move(linkService), std::move(transport));
147 accept(onFaceCreated, onAcceptFailed);
void setUri(const FaceUri &uri)
~UnixStreamChannel() override
detail::SimulatorIo & getGlobalIoService()
UnixStreamChannel-related error.
std::function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when a face fails to be created.
std::function< void(const shared_ptr< Face > &face)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
void connectFaceClosedSignal(Face &face, const std::function< void()> &f)
invokes a callback when the face is closed
#define NFD_LOG_CHAN_DEBUG(msg)
Log a message at DEBUG level.
Copyright (c) 2011-2015 Regents of the University of California.
#define NFD_LOG_CHAN_INFO(msg)
Log a message at INFO level.
#define NFD_LOG_CHAN_TRACE(msg)
Log a message at TRACE level.
Class implementing a local channel to create faces.
#define NFD_LOG_CHAN_WARN(msg)
Log a message at WARN level.
represents the underlying protocol and address used by a Face
bool isListening() const override
Returns whether the channel is listening.
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onAcceptFailed, int backlog=boost::asio::local::stream_protocol::acceptor::max_connections)
Start listening.
UnixStreamChannel(const unix_stream::Endpoint &endpoint, bool wantCongestionMarking)
Create UnixStream channel for the specified endpoint.
boost::asio::local::stream_protocol::endpoint Endpoint
#define NFD_LOG_INIT(name)