11#include <boost/enable_shared_from_this.hpp>
15using namespace boost::asio::local;
16namespace ph = std::placeholders;
47 void asyncConnect(
const stream_protocol::endpoint& endpoint,
63 const boost::system::error_code& ec);
74 void asyncSend(
const void* data,
const size_t length,
86 void doSend(
const boost::asio::const_buffers_1& buffer,
106 const boost::asio::const_buffers_1& buffer,
107 const boost::system::error_code& ec,
130 void doReceive(
const boost::asio::mutable_buffers_1& buffer,
149 const boost::asio::mutable_buffers_1& buffer,
150 const boost::system::error_code& ec,
175 socket_.async_connect(endpoint, local_handler);
180 const boost::system::error_code& ec) {
186 if (ec.value() == boost::asio::error::in_progress) {
187 remote_handler(boost::system::error_code());
196 doSend(boost::asio::buffer(data, length), handler);
204 handler, buffer, ph::_1, ph::_2);
205 socket_.async_send(buffer, local_handler);
210 const boost::asio::const_buffers_1& buffer,
211 const boost::system::error_code& ec,
217 if ((ec.value() == boost::asio::error::would_block) ||
218 (ec.value() == boost::asio::error::try_again)) {
219 doSend(buffer, remote_handler);
222 remote_handler(ec, length);
229 doReceive(boost::asio::buffer(data, length), handler);
237 handler, buffer, ph::_1, ph::_2);
238 socket_.async_receive(buffer, 0, local_handler);
243 const boost::asio::mutable_buffers_1& buffer,
244 const boost::system::error_code& ec,
250 if ((ec.value() == boost::asio::error::would_block) ||
251 (ec.value() == boost::asio::error::try_again)) {
255 remote_handler(ec, length);
261 boost::system::error_code ec;
262 static_cast<void>(
socket_.shutdown(stream_protocol::socket::shutdown_both, ec));
270 boost::system::error_code ec;
271 static_cast<void>(
socket_.cancel(ec));
279 boost::system::error_code ec;
280 static_cast<void>(
socket_.close(ec));
292#if BOOST_VERSION < 106600
293 return (impl_->socket_.native());
295 return (impl_->socket_.native_handle());
306 boost::system::error_code ec;
307 impl_->socket_.connect(stream_protocol::endpoint(path.c_str()), ec);
315 impl_->asyncConnect(stream_protocol::endpoint(path.c_str()), handler);
320 boost::system::error_code ec;
321 size_t res = boost::asio::write(impl_->socket_,
322 boost::asio::buffer(data, length),
323 boost::asio::transfer_all(),
334 impl_->asyncSend(data, length, handler);
339 boost::system::error_code ec;
340 size_t res = impl_->socket_.receive(boost::asio::buffer(data, length), 0, ec);
350 impl_->asyncReceive(data, length, handler);
368boost::asio::local::stream_protocol::socket&
370 return (impl_->socket_);
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.
UnixDomainSocketImpl(const IOServicePtr &io_service)
Constructor.
IOServicePtr io_service_
The IO service used to handle events.
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.
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.
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.
UnixDomainSocket(const IOServicePtr &io_service)
Constructor.
std::function< void(const boost::system::error_code &, size_t)> Handler
Callback type used in calls to UnixDomainSocket::asyncSend and UnixDomainSocket::asyncReceive.
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.
std::function< void(const boost::system::error_code &)> ConnectHandler
Callback type used in call to UnixDomainSocket::asyncConnect.
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.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
Defines the logger used by the top-level component of kea-lfc.