10 #ifndef BOOST_ASIO_HPP 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_;
158 template <
typename C>
160 socket_ptr_(NULL), socket_(socket), isopen_(true)
166 template <
typename C>
168 socket_ptr_(new
boost::asio::ip::udp::socket(service.get_io_service())),
169 socket_(*socket_ptr_), isopen_(false)
175 template <
typename C>
183 template <
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);
220 template <
typename C>
void 233 static_cast<const UDPEndpoint*>(endpoint);
236 socket_.async_send_to(boost::asio::buffer(data, length),
237 udp_endpoint->getASIOEndpoint(), callback);
240 "attempt to send on a UDP socket that is not open");
247 template <
typename C>
void 255 UDPEndpoint* udp_endpoint = static_cast<UDPEndpoint*>(endpoint);
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),
266 udp_endpoint->getASIOEndpoint(), callback);
269 "attempt to receive from a UDP socket that is not open");
276 template <
typename C>
bool 278 size_t& cumulative,
size_t& offset,
288 outbuff->writeData(staging, length);
296 template <
typename C>
void 306 template <
typename C>
void 308 if (isopen_ && socket_ptr_) {
317 #endif // UDP_SOCKET_H virtual int getNative() const
Return file descriptor of underlying socket.
The UDPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a UDP ...
virtual void cancel()
Cancel I/O On Socket.
virtual void close()
Close socket.
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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
virtual void open(const IOEndpoint *endpoint, C &callback)
Open Socket.
virtual void asyncReceive(void *data, size_t length, size_t offset, IOEndpoint *endpoint, C &callback)
Receive Asynchronously.
virtual short getFamily() const =0
Returns the address family of the endpoint.
The UDPSocket class is a concrete derived class of IOAsioSocket that represents a UDP socket.
virtual int getProtocol() const
Return protocol of socket.
virtual bool isOpenSynchronous() const
Is "open()" synchronous?
virtual void asyncSend(const void *data, size_t length, const IOEndpoint *endpoint, C &callback)
Send Asynchronously.
Defines the logger used by the top-level component of kea-dhcp-ddns.
A wrapper interface for the ASIO library.
I/O Socket with asynchronous operations.
boost::shared_ptr< OutputBuffer > OutputBufferPtr
virtual ~UDPSocket()
Destructor.
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.
The IOEndpoint class is an abstract base class to represent a communication endpoint.