33 #include <system_error>
40 bool wantCongestionMarking)
41 : m_endpoint(endpoint)
42 , m_wantCongestionMarking(wantCongestionMarking)
45 setUri(FaceUri(m_endpoint));
53 boost::system::error_code ec1;
54 m_acceptor.close(ec1);
57 std::filesystem::remove(m_endpoint.path(), ec2);
71 namespace fs = std::filesystem;
73 fs::path socketPath = m_endpoint.path();
75 fs::path parent = socketPath.parent_path();
76 if (!parent.empty() && fs::create_directories(parent)) {
80 auto type = fs::symlink_status(socketPath).type();
81 if (type == fs::file_type::socket) {
84 boost::system::error_code ec;
86 socket.connect(m_endpoint, ec);
90 NDN_THROW_NO_STACK(fs::filesystem_error(
"UnixStreamChannel::listen", socketPath,
91 std::make_error_code(std::errc::address_in_use)));
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_type::not_found) {
103 NDN_THROW_NO_STACK(fs::filesystem_error(
"UnixStreamChannel::listen", socketPath,
104 std::make_error_code(std::errc::not_a_socket)));
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::perms::owner_read | fs::perms::group_read | fs::perms::others_read |
123 fs::perms::owner_write | fs::perms::group_write | fs::perms::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.