Kea  1.9.9-git
io_acceptor.h
Go to the documentation of this file.
1 // Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef IO_ACCEPTOR_H
8 #define IO_ACCEPTOR_H
9 
10 #ifndef BOOST_ASIO_HPP
11 #error "asio.hpp must be included before including this, see asiolink.h as to why"
12 #endif
13 
14 #include <asiolink/io_service.h>
15 #include <asiolink/io_socket.h>
16 
17 namespace isc {
18 namespace asiolink {
19 
33 template<typename ProtocolType, typename CallbackType>
34 class IOAcceptor : public IOSocket {
35 public:
36 
40  explicit IOAcceptor(IOService& io_service)
41  : IOSocket(),
42  acceptor_(new typename ProtocolType::acceptor(io_service.get_io_service())) {
43  }
44 
46  virtual ~IOAcceptor() { }
47 
49  virtual int getNative() const {
50 #if BOOST_VERSION < 106600
51  return (acceptor_->native());
52 #else
53  return (acceptor_->native_handle());
54 #endif
55  }
56 
63  template<typename EndpointType>
64  void open(const EndpointType& endpoint) {
65  acceptor_->open(endpoint.getASIOEndpoint().protocol());
66  }
67 
74  template<typename EndpointType>
75  void bind(const EndpointType& endpoint) {
76  acceptor_->bind(endpoint.getASIOEndpoint());
77  }
78 
85  template<typename SettableSocketOption>
86  void setOption(const SettableSocketOption& socket_option) {
87  acceptor_->set_option(socket_option);
88  }
89 
91  void listen() {
92  acceptor_->listen();
93  }
94 
98  bool isOpen() const {
99  return (acceptor_->is_open());
100  }
101 
103  void close() const {
104  acceptor_->close();
105  }
106 
107 protected:
108 
120  template<typename SocketType>
121  void asyncAcceptInternal(const SocketType& socket,
122  const CallbackType& callback) {
123  acceptor_->async_accept(socket.getASIOSocket(), callback);
124  }
125 
126 
128  boost::shared_ptr<typename ProtocolType::acceptor> acceptor_;
129 
130 };
131 
132 
133 } // end of namespace asiolink
134 } // end of isc
135 
136 #endif // IO_ACCEPTOR_H
Defines the logger used by the top-level component of kea-dhcp-ddns.