Subject: [Boost-bugs] [Boost C++ Libraries] #4787: ASIO - adding support for accessing UDP control headers
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-10-25 18:31:22
#4787: ASIO - adding support for accessing UDP control headers
------------------------------+---------------------------------------------
Reporter: anonymous | Owner: chris_kohlhoff
Type: Patches | Status: new
Milestone: To Be Determined | Component: asio
Version: Boost 1.44.0 | Severity: Problem
Keywords: |
------------------------------+---------------------------------------------
Attached patch implements ASIO support for accessing optional UDP control
headers such as the timestamp information set with SO_TIMESTAMP.
Here are two ways of getting timestamp information using the new feature
of the patch. Note that it works in synchronous and asynchronous mode.
ip::udp::socket sock;
...
sock.set_option(ip::unicast::timestamp(true));
...
ip::udp::endpoint ep;
sock.receive_from(buf, ep, bytes_transferred);
boost::asio::detail::io_control::siocgstamp tv1;
for (const cmsghdr* cmsg = ep.control_header_first();
cmsg;
cmsg = ep.control_header_next(cmsg)) {
printf(" cmsg_len %zu: ", cmsg->cmsg_len);
switch (cmsg->cmsg_level) {
case SOL_SOCKET:
switch (cmsg->cmsg_type) {
case SO_TIMESTAMP: {
const timeval *stamp =
ep.control_msg_data<const timeval*>(cmsg);
printf("SO_TIMESTAMP %ld.%06ld",
(long)stamp->tv_sec,
(long)stamp->tv_usec);
tv1.set(*stamp);
break;
}
case SO_TIMESTAMPNS: {
const timespec* stamp =
ep.control_msg_data<const timespec*>(cmsg);
...
break;
}
default:
printf("type %d", cmsg->cmsg_type);
break;
}
break;
}
default:
printf("Level %d, Type %d", cmsg->cmsg_level,
cmsg->cmsg_type);
break;
}
}
// Alternative way of getting the last datagram's kernel timestamp
boost::asio::detail::io_control::siocgstamp tv;
boost::system::error_code ec;
boost::asio::detail::socket_ops::state_type client_state = 0;
boost::asio::detail::socket_ops::ioctl(
a_sock.native(), client_state, tv.name(), tv.data(), ec);
Hope it can be included in the release.
Regards,
Serge
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/4787> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:04 UTC