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)

boost_1_44_0.asio.patch (7.4 KB ) - added by saleyn@… 12 years ago.
Support of optional datagram control headers.
boost-ext.hpp (2.8 KB ) - added by saleyn@… 12 years ago.
Implementation of timestamp supporting socket options.
boost_1_44_0.asio.2.patch (8.5 KB ) - added by saleyn@… 12 years ago.
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.
so_timestamping.1.53.0.patch (6.5 KB ) - added by jason@… 9 years ago.
Updated patch for boost 1.53.0
so_timestamping.1.53.0.2.patch (6.6 KB ) - added by jason@… 9 years ago.
Improvement to previous patch for 1.53.0. These patches change the existing interfaces by adding additional parameters.

Download all attachments as: .zip

Change History (11)

by saleyn@…, 12 years ago

Attachment: boost_1_44_0.asio.patch added

Support of optional datagram control headers.

by saleyn@…, 12 years ago

Attachment: boost-ext.hpp added

Implementation of timestamp supporting socket options.

by saleyn@…, 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 Leonid Evdokimov <leon@…>, 11 years ago

Cc: leon@… added

comment:2 by jason@…, 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 jason@…, 9 years ago

Updated patch for boost 1.53.0

by jason@…, 9 years ago

Improvement to previous patch for 1.53.0. These patches change the existing interfaces by adding additional parameters.

comment:3 by pdurkan@…, 7 years ago

Is this patch working?

comment:4 by jason@…, 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:5 by saleyn@…, 7 years ago

Worked fine for me in 1.44.0. Haven't used that code since that version.

comment:6 by rpopescu@…, 7 years ago

Hello,

Why isn't this applied? We also would like support for SO_BUSY_POLL.

Thank you!

Note: See TracTickets for help on using tickets.