unix-stream-channel.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_FACE_UNIX_STREAM_CHANNEL_HPP
27 #define NFD_DAEMON_FACE_UNIX_STREAM_CHANNEL_HPP
28 
29 #include "channel.hpp"
30 
31 namespace nfd {
32 
33 namespace unix_stream {
34 typedef boost::asio::local::stream_protocol::endpoint Endpoint;
35 } // namespace unix_stream
36 
37 namespace face {
38 
45 class UnixStreamChannel : public Channel
46 {
47 public:
51  class Error : public std::runtime_error
52  {
53  public:
54  explicit
55  Error(const std::string& what)
56  : std::runtime_error(what)
57  {
58  }
59  };
60 
67  explicit
69 
70  ~UnixStreamChannel() override;
71 
72  bool
73  isListening() const override
74  {
75  return m_acceptor.is_open();
76  }
77 
78  size_t
79  size() const override
80  {
81  return m_size;
82  }
83 
99  void
100  listen(const FaceCreatedCallback& onFaceCreated,
101  const FaceCreationFailedCallback& onAcceptFailed,
102  int backlog = boost::asio::local::stream_protocol::acceptor::max_connections);
103 
104 private:
105  void
106  accept(const FaceCreatedCallback& onFaceCreated,
107  const FaceCreationFailedCallback& onAcceptFailed);
108 
109  void
110  handleAccept(const boost::system::error_code& error,
111  const FaceCreatedCallback& onFaceCreated,
112  const FaceCreationFailedCallback& onAcceptFailed);
113 
114 private:
115  const unix_stream::Endpoint m_endpoint;
116  boost::asio::local::stream_protocol::acceptor m_acceptor;
117  boost::asio::local::stream_protocol::socket m_socket;
118  size_t m_size;
119 };
120 
121 } // namespace face
122 } // namespace nfd
123 
124 #endif // NFD_DAEMON_FACE_UNIX_STREAM_CHANNEL_HPP
size_t size() const override
Returns the number of faces in the channel.
STL namespace.
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
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.
Definition: channel.hpp:44
represent a channel that communicates on a local endpoint
Definition: channel.hpp:52
bool isListening() const override
Returns whether the channel is listening.
Class implementing a local channel to create faces.
boost::asio::local::stream_protocol::endpoint Endpoint
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...
Definition: channel.hpp:35