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> 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();
155 std::unique_ptr<boost::asio::ip::udp::socket> socket_ptr_;
158 boost::asio::ip::udp::socket& socket_;
166 template <
typename C>
168 socket_ptr_(), socket_(socket), isopen_(true)
174 template <
typename C>
176 socket_ptr_(new
boost::asio::ip::udp::socket(service.get_io_service())),
177 socket_(*socket_ptr_), isopen_(false)
183 template <
typename C>
190 template <
typename C>
void 200 socket_.open(boost::asio::ip::udp::v4());
202 socket_.open(boost::asio::ip::udp::v6());
207 boost::asio::ip::udp::socket::send_buffer_size snd_size;
208 socket_.get_option(snd_size);
211 socket_.set_option(snd_size);
214 boost::asio::ip::udp::socket::receive_buffer_size rcv_size;
215 socket_.get_option(rcv_size);
218 socket_.set_option(rcv_size);
226 template <
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");
253 template <
typename C>
void 264 if (offset >= length) {
266 "UDP receive buffer");
268 void* buffer_start =
static_cast<void*
>(
static_cast<uint8_t*
>(data) + offset);
271 socket_.async_receive_from(boost::asio::buffer(buffer_start, length - offset),
272 udp_endpoint->getASIOEndpoint(), callback);
275 "attempt to receive from a UDP socket that is not open");
282 template <
typename C>
bool 284 size_t& cumulative,
size_t& offset,
294 outbuff->writeData(staging, length);
302 template <
typename C>
void 312 template <
typename C>
void 314 if (isopen_ && socket_ptr_) {
323 #endif // UDP_SOCKET_H virtual int getNative() const
Return file descriptor of underlying socket.
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
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-lfc.
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.