31 #include <boost/filesystem.hpp> 40 : m_endpoint(endpoint)
45 setUri(FaceUri(m_endpoint));
54 boost::system::error_code error;
55 m_acceptor.close(error);
57 boost::filesystem::remove(m_endpoint.path(), error);
71 namespace fs = boost::filesystem;
73 fs::path socketPath(m_endpoint.path());
74 fs::file_type type = fs::symlink_status(socketPath).type();
76 if (type == fs::socket_file) {
77 boost::system::error_code error;
79 socket.connect(m_endpoint, error);
83 BOOST_THROW_EXCEPTION(
Error(
"Socket file at " + m_endpoint.path()
84 +
" belongs to another NFD process"));
86 else if (error == boost::asio::error::connection_refused ||
87 error == boost::asio::error::timed_out) {
91 fs::remove(socketPath);
94 else if (type != fs::file_not_found) {
95 BOOST_THROW_EXCEPTION(
Error(m_endpoint.path() +
" already exists and is not a socket file"));
99 m_acceptor.bind(m_endpoint);
100 m_acceptor.listen(backlog);
102 if (::chmod(m_endpoint.path().c_str(), 0666) < 0) {
103 BOOST_THROW_EXCEPTION(
Error(
"chmod(" + m_endpoint.path() +
") failed: " + std::strerror(errno)));
106 accept(onFaceCreated, onAcceptFailed);
114 m_acceptor.async_accept(m_socket, bind(&UnixStreamChannel::handleAccept,
this,
115 boost::asio::placeholders::error,
116 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 auto linkService = make_unique<GenericLinkService>();
136 auto transport = make_unique<UnixStreamTransport>(std::move(m_socket));
137 auto face = make_shared<Face>(std::move(linkService), std::move(transport));
145 accept(onFaceCreated, onAcceptFailed);
UnixStreamChannel(const unix_stream::Endpoint &endpoint)
Create UnixStream channel for the specified endpoint.
void connectFaceClosedSignal(Face &face, const std::function< void()> &f)
invokes a callback when the 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.
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 setUri(const FaceUri &uri)
~UnixStreamChannel() override
bool isListening() const override
Returns whether the channel is listening.
#define NFD_LOG_INIT(name)
#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.
#define NFD_LOG_CHAN_DEBUG(msg)
Log a message at DEBUG level.
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
boost::asio::io_service & getGlobalIoService()