Opened 12 years ago
Last modified 7 years ago
#4787 new Patches
ASIO - adding support for accessing UDP control headers
Reported by: | anonymous | Owned by: | chris_kohlhoff |
---|---|---|---|
Milestone: | To Be Determined | Component: | asio |
Version: | Boost 1.44.0 | Severity: | Problem |
Keywords: | Cc: | saleyn@…, leon@… |
Description
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
Attachments (5)
Change History (11)
by , 12 years ago
Attachment: | boost_1_44_0.asio.patch added |
---|
by , 12 years ago
Attachment: | boost-ext.hpp added |
---|
Implementation of timestamp supporting socket options.
by , 12 years ago
Attachment: | boost_1_44_0.asio.2.patch added |
---|
Please use this patch instead - apparently when I ported the patch from 1.41.0 to 1.44.0 I previously missed to add support for non_blocking mode in 1.44.0.
comment:1 by , 11 years ago
Cc: | added |
---|
comment:2 by , 9 years ago
Is there a problem with the patch? I ask because it's still not in the release and is 3 years old.
Jason
by , 9 years ago
Attachment: | so_timestamping.1.53.0.2.patch added |
---|
Improvement to previous patch for 1.53.0. These patches change the existing interfaces by adding additional parameters.
comment:4 by , 7 years ago
It worked for me. However, we no longer use the related code so I'm unlikely to track this patch much more.
Regards, Jason
comment:6 by , 7 years ago
Hello,
Why isn't this applied? We also would like support for SO_BUSY_POLL.
Thank you!
Support of optional datagram control headers.