Kea 2.7.7
io_acceptor.h
Go to the documentation of this file.
1// Copyright (C) 2017-2025 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
17namespace isc {
18namespace asiolink {
19
33template<typename ProtocolType, typename CallbackType>
34class IOAcceptor : public IOSocket {
35public:
36
40 explicit IOAcceptor(const IOServicePtr& io_service)
41 : IOSocket(), io_service_(io_service),
42 acceptor_(new typename ProtocolType::acceptor(io_service_->getInternalIOService())) {
43 }
44
46 virtual ~IOAcceptor() { }
47
49 virtual int getNative() const {
50 return (acceptor_->native_handle());
51 }
52
59 template<typename EndpointType>
60 void open(const EndpointType& endpoint) {
61 acceptor_->open(endpoint.getASIOEndpoint().protocol());
62 }
63
70 template<typename EndpointType>
71 void bind(const EndpointType& endpoint) {
72 acceptor_->bind(endpoint.getASIOEndpoint());
73 }
74
81 template<typename SettableSocketOption>
82 void setOption(const SettableSocketOption& socket_option) {
83 acceptor_->set_option(socket_option);
84 }
85
87 void listen() {
88 acceptor_->listen();
89 }
90
94 bool isOpen() const {
95 return (acceptor_->is_open());
96 }
97
99 void close() const {
100 acceptor_->close();
101 }
102
103protected:
104
116 template<typename SocketType>
117 void asyncAcceptInternal(const SocketType& socket,
118 const CallbackType& callback) {
119 acceptor_->async_accept(socket.getASIOSocket(), callback);
120 }
121
124
126 boost::shared_ptr<typename ProtocolType::acceptor> acceptor_;
127
128};
129
130} // end of namespace asiolink
131} // end of isc
132
133#endif // IO_ACCEPTOR_H
Defines the logger used by the top-level component of kea-lfc.