Kea: unix_domain_socket.h Source File

| Kea 2.2.0

unix_domain_socket.h
Go to the documentation of this file.
1// Copyright (C) 2017 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 UNIX_DOMAIN_SOCKET_H
8#define UNIX_DOMAIN_SOCKET_H
9
10#include <asiolink/io_service.h>
11#include <asiolink/io_socket.h>
12#include <boost/shared_ptr.hpp>
13#include <functional>
14#include <string>
15
16namespace isc {
17namespace asiolink {
18
20 class UnixDomainSocketError : public Exception {
21public:
22 UnixDomainSocketError(const char* file, size_t line, const char* what) :
23 isc::Exception(file, line, what) { };
24};
25
26class UnixDomainSocketImpl;
27
30 class UnixDomainSocket : public IOSocket {
31public:
32
34 typedef std::function<void(const boost::system::error_code&)> ConnectHandler;
35
38 typedef std::function<void(const boost::system::error_code&, size_t)> Handler;
39
44 explicit UnixDomainSocket(IOService& io_service);
45
47 virtual int getNative() const;
48
50 virtual int getProtocol() const;
51
57 void connect(const std::string& path);
58
66 void asyncConnect(const std::string& path, const ConnectHandler& handler);
67
75 size_t write(const void* data, size_t length);
76
85 void asyncSend(const void* data, const size_t length, const Handler& handler);
86
95 size_t receive(void* data, size_t length);
96
105 void asyncReceive(void* data, const size_t length, const Handler& handler);
106
110 void shutdown();
111
115 void cancel();
116
120 void close();
121
125 virtual boost::asio::local::stream_protocol::socket& getASIOSocket() const;
126
127private:
128
130 boost::shared_ptr<UnixDomainSocketImpl> impl_;
131
132};
133
134} // end of namespace isc::asiolink
135} // end of namespace isc
136
137#endif // UNIX_DOMAIN_SOCKET_H
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::asiolink::IOService
The IOService class is a wrapper for the ASIO io_service class.
Definition: io_service.h:33
isc::asiolink::IOSocket
The IOSocket class is an abstract base class to represent various types of network sockets.
Definition: io_socket.h:37
isc::asiolink::UnixDomainSocketError
Exception thrown upon socket error.
Definition: unix_domain_socket.h:20
isc::asiolink::UnixDomainSocketError::UnixDomainSocketError
UnixDomainSocketError(const char *file, size_t line, const char *what)
Definition: unix_domain_socket.h:22
isc::asiolink::UnixDomainSocket
Represents unix domain socket implemented in terms of boost asio.
Definition: unix_domain_socket.h:30
isc::asiolink::UnixDomainSocket::Handler
std::function< void(const boost::system::error_code &, size_t)> Handler
Callback type used in calls to UnixDomainSocket::asyncSend and UnixDomainSocket::asyncReceive.
Definition: unix_domain_socket.h:38
isc::asiolink::UnixDomainSocket::close
void close()
Closes the socket.
Definition: unix_domain_socket.cc:361
isc::asiolink::UnixDomainSocket::asyncConnect
void asyncConnect(const std::string &path, const ConnectHandler &handler)
Asynchronously connects the socket to the specified endpoint.
Definition: unix_domain_socket.cc:311
isc::asiolink::UnixDomainSocket::asyncSend
void asyncSend(const void *data, const size_t length, const Handler &handler)
Asynchronously sends data over the socket.
Definition: unix_domain_socket.cc:329
isc::asiolink::UnixDomainSocket::write
size_t write(const void *data, size_t length)
Writes specified amount of data to a socket.
Definition: unix_domain_socket.cc:316
isc::asiolink::UnixDomainSocket::shutdown
void shutdown()
Disables read and write operations on the socket.
Definition: unix_domain_socket.cc:351
isc::asiolink::UnixDomainSocket::ConnectHandler
std::function< void(const boost::system::error_code &)> ConnectHandler
Callback type used in call to UnixDomainSocket::asyncConnect.
Definition: unix_domain_socket.h:34
isc::asiolink::UnixDomainSocket::receive
size_t receive(void *data, size_t length)
Receives data from a socket.
Definition: unix_domain_socket.cc:335
isc::asiolink::UnixDomainSocket::asyncReceive
void asyncReceive(void *data, const size_t length, const Handler &handler)
Asynchronously receives data over the socket.
Definition: unix_domain_socket.cc:345
isc::asiolink::UnixDomainSocket::UnixDomainSocket
UnixDomainSocket(IOService &io_service)
Constructor.
Definition: unix_domain_socket.cc:283
isc::asiolink::UnixDomainSocket::getASIOSocket
virtual boost::asio::local::stream_protocol::socket & getASIOSocket() const
Returns reference to the underlying ASIO socket.
Definition: unix_domain_socket.cc:366
isc::asiolink::UnixDomainSocket::getNative
virtual int getNative() const
Returns native socket representation.
Definition: unix_domain_socket.cc:288
isc::asiolink::UnixDomainSocket::getProtocol
virtual int getProtocol() const
Always returns 0.
Definition: unix_domain_socket.cc:297
isc::asiolink::UnixDomainSocket::connect
void connect(const std::string &path)
Connects the socket to the specified endpoint.
Definition: unix_domain_socket.cc:302
isc::asiolink::UnixDomainSocket::cancel
void cancel()
Cancels scheduled asynchronous operations on the socket.
Definition: unix_domain_socket.cc:356
io_service.h
io_socket.h
asiolink
A wrapper interface for the ASIO library.
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143