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,
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));
147 accept(onFaceCreated, onAcceptFailed);