32 #include <boost/filesystem.hpp> 41 bool wantCongestionMarking)
42 : m_endpoint(endpoint)
46 , m_wantCongestionMarking(wantCongestionMarking)
48 setUri(FaceUri(m_endpoint));
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) {
105 NDN_THROW_ERRNO(
Error(
"Failed to chmod " + m_endpoint.path()));
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());
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));
140 face->setChannel(shared_from_this());
148 accept(onFaceCreated, onAcceptFailed);
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_INFO(msg)
Log a message at INFO level.
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onAcceptFailed, int backlog=boost::asio::local::stream_protocol::acceptor::max_connections)
Start listening.
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
UnixStreamChannel-related error.
void setUri(const FaceUri &uri)
Options that control the behavior of GenericLinkService.
~UnixStreamChannel() override
bool isListening() const override
Returns whether the channel is listening.
#define NFD_LOG_INIT(name)
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...
#define NFD_LOG_CHAN_TRACE(msg)
Log a message at TRACE level.
boost::asio::local::stream_protocol::endpoint Endpoint
#define NFD_LOG_CHAN_WARN(msg)
Log a message at WARN level.
bool allowCongestionMarking
enables send queue congestion detection and marking
UnixStreamChannel(const unix_stream::Endpoint &endpoint, bool wantCongestionMarking)
Create UnixStream channel for the specified endpoint.
#define NFD_LOG_CHAN_DEBUG(msg)
Log a message at DEBUG level.
boost::asio::io_service & getGlobalIoService()
Returns the global io_service instance for the calling thread.