Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2832: Asio sync IO functions need timeout parameters
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-01-13 08:54:01
#2832: Asio sync IO functions need timeout parameters
-----------------------------------------------------+----------------------
Reporter: Stephan Menzel <stephan.menzel@â¦> | Owner: chris_kohlhoff
Type: Bugs | Status: reopened
Milestone: Boost 1.39.0 | Component: asio
Version: Boost 1.38.0 | Severity: Problem
Resolution: | Keywords:
-----------------------------------------------------+----------------------
Changes (by stephan.menzel@â¦):
* status: closed => reopened
* resolution: wontfix =>
Comment:
Hi Chris,
I guess I have to work through this disappointment then.... And yet, if
there are no use cases and the situation is good as it is, how come the
topic pops up in both asio and boost mailing list with such a regularity?
My code has now several unportable spots in one lib caused entirely by
this. Whenever things have to go synchronous, I have to workaround that
way:
Example snippet UDP request/answer:
asio::ip::udp::endpoint sender_endpoint;
asio::ip::udp::socket socket(m_iosrv, asio::ip::udp::v4());
socket.send_to(asio::buffer(requeststring), m_pwh_master_ep);
asio::ip::udp::socket::native_type native_sock = socket.native();
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(native_sock, &rfds);
struct timeval tv;
tv.tv_sec = 42;
tv.tv_usec = 0;
if (!select(native_sock + 1, &rfds, NULL, NULL, &tv)) {
THROW(net_error, "timeout reading from socket");
}
size_t reply_length =
socket.receive_from(asio::buffer(reply, udp_max_length),
sender_endpoint);
...and so forth and suchlike.
Is that really what you want asio code to look like?
Realizing this with a timer would be OK for me and I tried but this
doesn't work because the timers cannot cancel syncronous operations.
Behold your very own docs:
http://www.boost.org/doc/libs/1_41_0/doc/html/boost_asio/reference/basic_datagram_socket/cancel.html
It clearly says "cancel all asynchronous operations" so I can't timeout a
sync_read with it.
Once I go in these synchronous functions asio appears not to offer any
kind of defined way out of it. Please correct me if I'm wrong but all the
answers to all the questions on the lists always boiled down to this.
If the given solutions are not viable, well that's alright with me. Just
tried to help. But in any case the topic needs to be addressed.
By the way, If you say "They're in POSIX this way so they're staying in
asio this way.", can you clearify that? In my example I have to go down to
select, which has a timeout and solves the problem. Besides, I doubt very
much this is a valid point. The whole boost is about offering stuff that
should be cross platform standard but is not yet. Does POSIX offer
regexes, time localisation, string formatting or parsing? Boost offers
lots of such things and if plain POSIX is enough and everything on top of
it is unnecessary, what's the point of having asio or indeed boost anyway?
Sorry for being so stubborn and verbose but I urge you to reconsider this.
I'm sure there must be a way.
Cheers,
Stephan
BTW:
Milestone 1.39, so take your time, no rush ;-)
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/2832#comment:3> 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:02 UTC