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
236 socket_.async_send_to(boost::asio::buffer(data, length),
240 "attempt to send on a UDP socket that is not open");
247 template <
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");
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