32 #include <boost/filesystem/exception.hpp>
33 #include <boost/filesystem/operations.hpp>
34 #include <boost/filesystem/path.hpp>
41 bool wantCongestionMarking)
42 : m_endpoint(endpoint)
43 , m_wantCongestionMarking(wantCongestionMarking)
46 setUri(FaceUri(m_endpoint));
54 boost::system::error_code ec;
57 boost::filesystem::remove(m_endpoint.path(), ec);
71 namespace fs = boost::filesystem;
73 fs::path socketPath = m_endpoint.path();
75 fs::path parent = socketPath.parent_path();
76 if (!parent.empty() && fs::create_directories(parent)) {
80 boost::system::error_code ec;
81 fs::file_type type = fs::symlink_status(socketPath).type();
82 if (type == fs::socket_file) {
86 socket.connect(m_endpoint, ec);
90 ec = boost::system::errc::make_error_code(boost::system::errc::address_in_use);
91 NDN_THROW_NO_STACK(fs::filesystem_error(
"UnixStreamChannel::listen", socketPath, ec));
93 else if (ec == boost::asio::error::connection_refused ||
94 ec == boost::asio::error::timed_out) {
97 fs::remove(socketPath);
100 else if (type != fs::file_not_found) {
103 ec = boost::system::errc::make_error_code(boost::system::errc::not_a_socket);
104 NDN_THROW_NO_STACK(fs::filesystem_error(
"UnixStreamChannel::listen", socketPath, ec));
109 m_acceptor.bind(m_endpoint);
110 m_acceptor.listen(backlog);
112 catch (
const boost::system::system_error& e) {
114 NDN_THROW_NO_STACK(fs::filesystem_error(
"UnixStreamChannel::listen: "s + e.std::runtime_error::what(),
115 socketPath, e.code()));
120 m_isListening =
true;
122 fs::permissions(socketPath, fs::owner_read | fs::group_read | fs::others_read |
123 fs::owner_write | fs::group_write | fs::others_write);
125 accept(onFaceCreated, onAcceptFailed);
133 m_acceptor.async_accept([=] (
const boost::system::error_code& error,
134 boost::asio::local::stream_protocol::socket socket) {
136 if (error != boost::asio::error::operation_aborted) {
139 onAcceptFailed(500,
"Accept failed: " + error.message());
148 auto linkService = make_unique<GenericLinkService>(options);
149 auto transport = make_unique<UnixStreamTransport>(std::move(socket));
150 auto face = make_shared<Face>(std::move(linkService), std::move(transport));
151 face->setChannel(weak_from_this());
159 accept(onFaceCreated, onAcceptFailed);
void setUri(const FaceUri &uri) noexcept
GenericLinkServiceOptions Options
Options for GenericLinkService.
bool isListening() const final
Returns whether the channel is listening.
UnixStreamChannel(const unix_stream::Endpoint &endpoint, bool wantCongestionMarking)
Create a UnixStream channel for the specified endpoint.
~UnixStreamChannel() final
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onAcceptFailed, int backlog=boost::asio::socket_base::max_listen_connections)
Start listening.
#define NFD_LOG_CHAN_DEBUG(msg)
Log a message at DEBUG level.
#define NFD_LOG_CHAN_INFO(msg)
Log a message at INFO level.
#define NFD_LOG_CHAN_WARN(msg)
Log a message at WARN level.
#define NFD_LOG_CHAN_TRACE(msg)
Log a message at TRACE level.
#define NFD_LOG_INIT(name)
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 > &)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
void connectFaceClosedSignal(Face &face, std::function< void()> f)
Invokes a callback when a face is closed.
boost::asio::local::stream_protocol::endpoint Endpoint
boost::asio::io_context & getGlobalIoService()
Returns the global io_context instance for the calling thread.
bool allowCongestionMarking
Enables send queue congestion detection and marking.