32 #include <boost/filesystem.hpp> 41 bool wantCongestionMarking)
42 : m_endpoint(endpoint)
46 , m_wantCongestionMarking(wantCongestionMarking)
57 boost::system::error_code error;
58 m_acceptor.close(error);
60 boost::filesystem::remove(m_endpoint.path(), error);
74 namespace fs = boost::filesystem;
76 fs::path socketPath(m_endpoint.path());
77 fs::file_type type = fs::symlink_status(socketPath).type();
79 if (type == fs::socket_file) {
80 boost::system::error_code error;
82 socket.connect(m_endpoint, error);
86 NDN_THROW(
Error(
"Socket file at " + m_endpoint.path() +
" 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 NDN_THROW(
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) {
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,
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));
140 face->setChannel(shared_from_this());
148 accept(onFaceCreated, onAcceptFailed);
void setUri(const FaceUri &uri)
#define NFD_LOG_INIT(name)
Accept any value the remote endpoint offers.
bool isListening() const final
Returns whether the channel is listening.
detail::SimulatorIo & getGlobalIoService()
Returns the global io_service instance for the calling thread.
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.
void connectFaceClosedSignal(Face &face, std::function< void()> f)
Invokes a callback when a face is closed.
#define NFD_LOG_CHAN_DEBUG(msg)
Log a message at DEBUG level.
~UnixStreamChannel() final
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
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.
std::function< void(const shared_ptr< Face > &)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
boost::asio::local::stream_protocol::endpoint Endpoint
Catch-all error for socket component errors that don't fit in other categories.
#define NDN_THROW_ERRNO(e)