11#error "asio.hpp must be included before including this, see asiolink.h as to why"
14#include <netinet/in.h>
15#include <sys/socket.h>
51 UDPSocket(boost::asio::ip::udp::socket& socket);
66#if BOOST_VERSION < 106600
67 return (socket_.native());
69 return (socket_.native_handle());
105 virtual void asyncSend(
const void* data,
size_t length,
119 virtual void asyncReceive(
void* data,
size_t length,
size_t offset,
138 size_t& cumulative,
size_t& offset,
146 virtual void close();
158 std::unique_ptr<boost::asio::ip::udp::socket> socket_ptr_;
161 boost::asio::ip::udp::socket& socket_;
171 socket_ptr_(), socket_(socket), isopen_(true) {
178 socket_ptr_(new
boost::asio::ip::udp::socket(io_service_->getInternalIOService())),
179 socket_(*socket_ptr_), isopen_(false) {
191template <
typename C>
void
200 if (endpoint->getFamily() == AF_INET) {
201 socket_.open(boost::asio::ip::udp::v4());
203 socket_.open(boost::asio::ip::udp::v6());
208 boost::asio::ip::udp::socket::send_buffer_size snd_size;
209 socket_.get_option(snd_size);
210 if (snd_size.value() < MIN_SIZE) {
212 socket_.set_option(snd_size);
215 boost::asio::ip::udp::socket::receive_buffer_size rcv_size;
216 socket_.get_option(rcv_size);
217 if (rcv_size.value() < MIN_SIZE) {
219 socket_.set_option(rcv_size);
227template <
typename C>
void
242 socket_.async_send_to(boost::asio::buffer(data, length),
243 udp_endpoint->getASIOEndpoint(), callback);
246 "attempt to send on a UDP socket that is not open");
253template <
typename C>
void
263 if (offset >= length) {
265 "UDP receive buffer");
267 void* buffer_start =
static_cast<void*
>(
static_cast<uint8_t*
>(data) + offset);
270 socket_.async_receive_from(boost::asio::buffer(buffer_start, length - offset),
271 udp_endpoint->getASIOEndpoint(), callback);
274 "attempt to receive from a UDP socket that is not open");
281template <
typename C>
bool
283 size_t& cumulative,
size_t& offset,
292 outbuff->writeData(staging, length);
300template <
typename C>
void
310template <
typename C>
void
312 if (isopen_ && socket_ptr_) {
I/O Socket with asynchronous operations.
The IOEndpoint class is an abstract base class to represent a communication endpoint.
The UDPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a UDP ...
The UDPSocket class is a concrete derived class of IOAsioSocket that represents a UDP socket.
virtual bool processReceivedData(const void *staging, size_t length, size_t &cumulative, size_t &offset, size_t &expected, isc::util::OutputBufferPtr &buff)
Process received data.
virtual bool isOpenSynchronous() const
Is "open()" synchronous?
virtual void asyncSend(const void *data, size_t length, const IOEndpoint *endpoint, C &callback)
Send Asynchronously.
virtual int getProtocol() const
Return protocol of socket.
virtual int getNative() const
Return file descriptor of underlying socket.
virtual void cancel()
Cancel I/O On Socket.
virtual void asyncReceive(void *data, size_t length, size_t offset, IOEndpoint *endpoint, C &callback)
Receive Asynchronously.
virtual void close()
Close socket.
virtual void open(const IOEndpoint *endpoint, C &callback)
Open Socket.
virtual ~UDPSocket()
Destructor.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
A wrapper interface for the ASIO library.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Type of pointers to output buffers.
Defines the logger used by the top-level component of kea-lfc.