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> 
   35class UDPSocket : 
public IOAsioSocket<C> {
 
   38    UDPSocket(
const UDPSocket&);
 
   39    UDPSocket& operator=(
const UDPSocket&);
 
   66        return (socket_.native_handle());
 
 
  134                                     size_t& cumulative, 
size_t& offset,
 
  154    std::unique_ptr<boost::asio::ip::udp::socket> socket_ptr_;
 
  157    boost::asio::ip::udp::socket& socket_;
 
 
  166UDPSocket<C>::UDPSocket(boost::asio::ip::udp::socket& socket) :
 
  167    socket_ptr_(), socket_(socket), isopen_(true) {
 
 
  173UDPSocket<C>::UDPSocket(
const IOServicePtr& io_service) : io_service_(io_service),
 
  174    socket_ptr_(new boost::asio::ip::udp::socket(io_service_->getInternalIOService())),
 
  175    socket_(*socket_ptr_), isopen_(false) {
 
 
  187template <
typename C> 
void 
  197            socket_.open(boost::asio::ip::udp::v4());
 
  199            socket_.open(boost::asio::ip::udp::v6());
 
  204        boost::asio::ip::udp::socket::send_buffer_size snd_size;
 
  205        socket_.get_option(snd_size);
 
  208            socket_.set_option(snd_size);
 
  211        boost::asio::ip::udp::socket::receive_buffer_size rcv_size;
 
  212        socket_.get_option(rcv_size);
 
  215            socket_.set_option(rcv_size);
 
 
  223template <
typename C> 
void 
  238        socket_.async_send_to(boost::asio::buffer(
data, length),
 
  242            "attempt to send on a UDP socket that is not open");
 
 
  249template <
typename C> 
void 
  259        if (offset >= length) {
 
  261                                      "UDP receive buffer");
 
  263        void* buffer_start = 
static_cast<void*
>(
static_cast<uint8_t*
>(
data) + offset);
 
  266        socket_.async_receive_from(boost::asio::buffer(buffer_start, length - offset),
 
  270            "attempt to receive from a UDP socket that is not open");
 
 
  277template <
typename C> 
bool 
  279                                  size_t& cumulative, 
size_t& offset,
 
  288    outbuff->writeData(staging, length);
 
 
  296template <
typename C> 
void 
  306template <
typename C> 
void 
  308    if (isopen_ && socket_ptr_) {
 
 
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 UDPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a UDP ...
const boost::asio::ip::udp::endpoint & getASIOEndpoint() const
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.
UDPSocket(const IOServicePtr &service)
Constructor.
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.
UDPSocket(boost::asio::ip::udp::socket &socket)
Constructor from an ASIO UDP 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.
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.