Kea 2.7.5
io_acceptor.h
Go to the documentation of this file.
1// Copyright (C) 2017-2024 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#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
107protected:
108
120 template<typename SocketType>
121 void asyncAcceptInternal(const SocketType& socket,
122 const CallbackType& callback) {
123 acceptor_->async_accept(socket.getASIOSocket(), callback);
124 }
125
128
130 boost::shared_ptr<typename ProtocolType::acceptor> acceptor_;
131
132};
133
134} // end of namespace asiolink
135} // end of isc
136
137#endif // IO_ACCEPTOR_H
Defines the logger used by the top-level component of kea-lfc.