Kea 2.7.9
io_asio_socket.h
Go to the documentation of this file.
1// Copyright (C) 2010-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_ASIO_SOCKET_H
8#define IO_ASIO_SOCKET_H 1
9
10// IMPORTANT NOTE: only very few ASIO headers files can be included in
11// this file. In particular, asio.hpp should never be included here.
12// See the description of the namespace below.
13#include <config.h>
14
15
17#include <asiolink/io_error.h>
18#include <asiolink/io_socket.h>
19#include <util/buffer.h>
20
21#include <functional>
22#include <string>
23
24#include <unistd.h> // for some network system calls
25
26#include <boost/asio/coroutine.hpp>
27
28namespace isc {
29namespace asiolink {
30
34class SocketNotOpen : public IOError {
35public:
36 SocketNotOpen(const char* file, size_t line, const char* what) :
37 IOError(file, line, what) {}
38};
39
43class SocketSetError : public IOError {
44public:
45 SocketSetError(const char* file, size_t line, const char* what) :
46 IOError(file, line, what) {}
47};
48
53class BufferOverflow : public IOError {
54public:
55 BufferOverflow(const char* file, size_t line, const char* what) :
56 IOError(file, line, what) {}
57};
58
60class IOEndpoint;
61
62
80
81template <typename C>
82class IOAsioSocket : public IOSocket {
83
89
90private:
91 IOAsioSocket(const IOAsioSocket<C>& source);
92 IOAsioSocket& operator=(const IOAsioSocket<C>& source);
93protected:
99public:
101 virtual ~IOAsioSocket() = default;
103
123 virtual int getNative() const = 0;
124
133 virtual int getProtocol() const = 0;
134
161 virtual bool isOpenSynchronous() const = 0;
162
175 virtual void open(const IOEndpoint* endpoint, C& callback) = 0;
176
187 virtual void asyncSend(const void* data, size_t length,
188 const IOEndpoint* endpoint, C& callback) = 0;
189
206 virtual void asyncReceive(void* data, size_t length, size_t offset,
207 IOEndpoint* endpoint, C& callback) = 0;
208
263 virtual bool processReceivedData(const void* staging, size_t length,
264 size_t& cumulative,
265 size_t& offset, size_t& expected,
267
269 virtual void cancel() = 0;
270
272 virtual void close() = 0;
273};
274
275
284
285template <typename C>
286class DummyAsioSocket : public IOAsioSocket<C> {
287private:
288 DummyAsioSocket(const DummyAsioSocket<C>& source);
289 DummyAsioSocket& operator=(const DummyAsioSocket<C>& source);
290public:
297 DummyAsioSocket(const int protocol) : protocol_(protocol) {}
298
303 virtual int getNative() const { return (-1); }
304
308 virtual int getProtocol() const { return (protocol_); }
309
310
314 bool isOpenSynchronous() const {
315 return true;
316 }
317
325 virtual bool open(const IOEndpoint*, C&) {
326 return (false);
327 }
328
333 virtual void asyncSend(const void*, size_t, const IOEndpoint*, C&) {
334 }
335
340 virtual void asyncReceive(void*, size_t, size_t, IOEndpoint*, C&) {
341 }
342
347 virtual bool receiveComplete(const void*, size_t, size_t&, size_t&,
349 {
350 return (true);
351 }
352
353
357 virtual void cancel() {
358 }
359
363 virtual void close() {
364 }
365
366private:
367 const int protocol_;
368};
369
370} // namespace asiolink
371} // namespace isc
372
373#endif // IO_ASIO_SOCKET_H
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Type of pointers to output buffers.
Definition buffer.h:574
Defines the logger used by the top-level component of kea-lfc.