11#include <boost/bind.hpp>
12#include <boost/enable_shared_from_this.hpp>
14using namespace boost::asio::local;
27 :
socket_(io_service.get_io_service()) {
45 void asyncConnect(
const stream_protocol::endpoint& endpoint,
61 const boost::system::error_code& ec);
72 void asyncSend(
const void* data,
const size_t length,
84 void doSend(
const boost::asio::const_buffers_1& buffer,
104 const boost::asio::const_buffers_1& buffer,
105 const boost::system::error_code& ec,
128 void doReceive(
const boost::asio::mutable_buffers_1& buffer,
147 const boost::asio::mutable_buffers_1& buffer,
148 const boost::system::error_code& ec,
169 socket_.async_connect(endpoint, local_handler);
174 const boost::system::error_code& ec) {
180 if (ec.value() == boost::asio::error::in_progress) {
181 remote_handler(boost::system::error_code());
190 doSend(boost::asio::buffer(data, length), handler);
197 handler, buffer, _1, _2);
198 socket_.async_send(buffer, local_handler);
203 const boost::asio::const_buffers_1& buffer,
204 const boost::system::error_code& ec,
210 if ((ec.value() == boost::asio::error::would_block) ||
211 (ec.value() == boost::asio::error::try_again)) {
212 doSend(buffer, remote_handler);
215 remote_handler(ec, length);
222 doReceive(boost::asio::buffer(data, length), handler);
229 handler, buffer, _1, _2);
230 socket_.async_receive(buffer, 0, local_handler);
235 const boost::asio::mutable_buffers_1& buffer,
236 const boost::system::error_code& ec,
242 if ((ec.value() == boost::asio::error::would_block) ||
243 (ec.value() == boost::asio::error::try_again)) {
247 remote_handler(ec, length);
253 boost::system::error_code ec;
254 static_cast<void>(
socket_.shutdown(stream_protocol::socket::shutdown_both, ec));
262 boost::system::error_code ec;
263 static_cast<void>(
socket_.cancel(ec));
271 boost::system::error_code ec;
272 static_cast<void>(
socket_.close(ec));
284#if BOOST_VERSION < 106600
285 return (impl_->socket_.native());
287 return (impl_->socket_.native_handle());
298 boost::system::error_code ec;
299 impl_->socket_.connect(stream_protocol::endpoint(path.c_str()), ec);
307 impl_->asyncConnect(stream_protocol::endpoint(path.c_str()), handler);
312 boost::system::error_code ec;
313 size_t res = boost::asio::write(impl_->socket_,
314 boost::asio::buffer(data, length),
315 boost::asio::transfer_all(),
326 impl_->asyncSend(data, length, handler);
331 boost::system::error_code ec;
332 size_t res = impl_->socket_.receive(boost::asio::buffer(data, length), 0, ec);
342 impl_->asyncReceive(data, length, handler);
360boost::asio::local::stream_protocol::socket&
362 return (impl_->socket_);
The IOService class is a wrapper for the ASIO io_service class.
Exception thrown upon socket error.
Implementation of the unix domain socket.
void cancel()
Cancels asynchronous operations on the socket.
void doSend(const boost::asio::const_buffers_1 &buffer, const UnixDomainSocket::Handler &handler)
Asynchronously sends the data over the socket.
stream_protocol::socket socket_
Instance of the boost asio unix domain socket.
void receiveHandler(const UnixDomainSocket::Handler &remote_handler, const boost::asio::mutable_buffers_1 &buffer, const boost::system::error_code &ec, size_t length)
Local handler invoked as a result of asynchronous receive.
void shutdown()
Disables read and write operations on the socket.
void asyncSend(const void *data, const size_t length, const UnixDomainSocket::Handler &handler)
Asynchronously sends data over the socket.
void doReceive(const boost::asio::mutable_buffers_1 &buffer, const UnixDomainSocket::Handler &handler)
Asynchronously receives the data over the socket.
void asyncConnect(const stream_protocol::endpoint &endpoint, const UnixDomainSocket::ConnectHandler &handler)
Asynchronously connects to an endpoint.
void connectHandler(const UnixDomainSocket::ConnectHandler &remote_handler, const boost::system::error_code &ec)
Local handler invoked as a result of asynchronous connection.
UnixDomainSocketImpl(IOService &io_service)
Constructor.
void sendHandler(const UnixDomainSocket::Handler &remote_handler, const boost::asio::const_buffers_1 &buffer, const boost::system::error_code &ec, size_t length)
Local handler invoked as a result of asynchronous send.
void asyncReceive(void *data, const size_t length, const UnixDomainSocket::Handler &handler)
Asynchronously receive data over the socket.
void close()
Closes the socket.
~UnixDomainSocketImpl()
Destructor.
std::function< void(const boost::system::error_code &, size_t)> Handler
Callback type used in calls to UnixDomainSocket::asyncSend and UnixDomainSocket::asyncReceive.
void close()
Closes the socket.
void asyncConnect(const std::string &path, const ConnectHandler &handler)
Asynchronously connects the socket to the specified endpoint.
void asyncSend(const void *data, const size_t length, const Handler &handler)
Asynchronously sends data over the socket.
size_t write(const void *data, size_t length)
Writes specified amount of data to a socket.
void shutdown()
Disables read and write operations on the socket.
std::function< void(const boost::system::error_code &)> ConnectHandler
Callback type used in call to UnixDomainSocket::asyncConnect.
size_t receive(void *data, size_t length)
Receives data from a socket.
void asyncReceive(void *data, const size_t length, const Handler &handler)
Asynchronously receives data over the socket.
UnixDomainSocket(IOService &io_service)
Constructor.
virtual boost::asio::local::stream_protocol::socket & getASIOSocket() const
Returns reference to the underlying ASIO socket.
virtual int getNative() const
Returns native socket representation.
virtual int getProtocol() const
Always returns 0.
void connect(const std::string &path)
Connects the socket to the specified endpoint.
void cancel()
Cancels scheduled asynchronous operations on the socket.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A wrapper interface for the ASIO library.
Defines the logger used by the top-level component of kea-dhcp-ddns.