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>
49 UDPSocket(boost::asio::ip::udp::socket& socket);
64#if BOOST_VERSION < 106600
65 return (socket_.native());
67 return (socket_.native_handle());
103 virtual void asyncSend(
const void* data,
size_t length,
117 virtual void asyncReceive(
void* data,
size_t length,
size_t offset,
136 size_t& cumulative,
size_t& offset,
144 virtual void close();
151 boost::asio::ip::udp::socket* socket_ptr_;
152 boost::asio::ip::udp::socket& socket_;
160 socket_ptr_(NULL), socket_(socket), isopen_(true)
168 socket_ptr_(new
boost::asio::ip::udp::socket(service.get_io_service())),
169 socket_(*socket_ptr_), isopen_(false)
183template <
typename C>
void
193 socket_.open(boost::asio::ip::udp::v4());
196 socket_.open(boost::asio::ip::udp::v6());
201 boost::asio::ip::udp::socket::send_buffer_size snd_size;
202 socket_.get_option(snd_size);
203 if (snd_size.value() < MIN_SIZE) {
205 socket_.set_option(snd_size);
208 boost::asio::ip::udp::socket::receive_buffer_size rcv_size;
209 socket_.get_option(rcv_size);
210 if (rcv_size.value() < MIN_SIZE) {
212 socket_.set_option(rcv_size);
220template <
typename C>
void
236 socket_.async_send_to(boost::asio::buffer(data, length),
240 "attempt to send on a UDP socket that is not open");
247template <
typename C>
void
258 if (offset >= length) {
260 "UDP receive buffer");
262 void* buffer_start =
static_cast<void*
>(
static_cast<uint8_t*
>(data) + offset);
265 socket_.async_receive_from(boost::asio::buffer(buffer_start, length - offset),
269 "attempt to receive from a UDP socket that is not open");
276template <
typename C>
bool
278 size_t& cumulative,
size_t& offset,
288 outbuff->writeData(staging, length);
296template <
typename C>
void
306template <
typename C>
void
308 if (isopen_ && socket_ptr_) {
I/O Socket with asynchronous operations.
The IOEndpoint class is an abstract base class to represent a communication endpoint.
virtual short getFamily() const =0
Returns the address family of the endpoint.
virtual short getProtocol() const =0
Returns the protocol number of the endpoint (TCP, UDP...)
The IOService class is a wrapper for the ASIO io_service class.
The UDPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a UDP ...
const boost::asio::ip::udp::endpoint & getASIOEndpoint() const
The UDPSocket class is a concrete derived class of IOAsioSocket that represents a UDP socket.
virtual bool isOpenSynchronous() const
Is "open()" synchronous?
virtual void asyncSend(const void *data, size_t length, const IOEndpoint *endpoint, C &callback)
Send Asynchronously.
virtual bool processReceivedData(const void *staging, size_t length, size_t &cumulative, size_t &offset, size_t &expected, isc::util::OutputBufferPtr &outbuff)
Process received data.
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.
A wrapper interface for the ASIO library.
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Defines the logger used by the top-level component of kea-dhcp-ddns.