diff options
author | Josh Blum <josh@joshknows.com> | 2010-03-04 18:34:28 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-03-04 18:34:28 -0800 |
commit | bb86022d5a5f7055cdeebaeb4a55216e1a056fd4 (patch) | |
tree | 8dd96e7b0fcef00fde57da97d44e012cc6177670 /host/lib/transport/udp_simple.cpp | |
parent | 821c31417894bed5603dc1a18415d4a35ddd7c2d (diff) | |
download | uhd-bb86022d5a5f7055cdeebaeb4a55216e1a056fd4.tar.gz uhd-bb86022d5a5f7055cdeebaeb4a55216e1a056fd4.tar.bz2 uhd-bb86022d5a5f7055cdeebaeb4a55216e1a056fd4.zip |
Moved timeouts into the udp transports.
Simplified the fast path checking in the fw, but it turns out this was not the issue.
Fixed some bad bit operations with the 16sc words (dont forget sign extension).
Added some more documentation to the headers....
Diffstat (limited to 'host/lib/transport/udp_simple.cpp')
-rw-r--r-- | host/lib/transport/udp_simple.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/host/lib/transport/udp_simple.cpp b/host/lib/transport/udp_simple.cpp index 491cf59db..7004bdfdf 100644 --- a/host/lib/transport/udp_simple.cpp +++ b/host/lib/transport/udp_simple.cpp @@ -16,12 +16,35 @@ // #include <uhd/transport/udp_simple.hpp> +#include <boost/thread.hpp> #include <boost/format.hpp> #include <iostream> using namespace uhd::transport; /*********************************************************************** + * Helper Functions + **********************************************************************/ +/*! + * A receive timeout for a socket: + * + * It seems that asio cannot have timeouts with synchronous io. + * However, we can implement a polling loop that will timeout. + * This is okay bacause this is the slow-path implementation. + * + * \param socket the asio socket + */ +static void reasonable_recv_timeout( + boost::asio::ip::udp::socket &socket +){ + boost::asio::deadline_timer timer(socket.get_io_service()); + timer.expires_from_now(boost::posix_time::milliseconds(50)); + while (not (socket.available() or timer.expires_from_now().is_negative())){ + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + } +} + +/*********************************************************************** * UDP connected implementation class **********************************************************************/ class udp_connected_impl : public udp_simple{ @@ -62,7 +85,8 @@ size_t udp_connected_impl::send(const boost::asio::const_buffer &buff){ } size_t udp_connected_impl::recv(const boost::asio::mutable_buffer &buff){ - if (_socket->available() == 0) return 0; + reasonable_recv_timeout(*_socket); + if (not _socket->available()) return 0; return _socket->receive(boost::asio::buffer(buff)); } @@ -112,7 +136,8 @@ size_t udp_broadcast_impl::send(const boost::asio::const_buffer &buff){ } size_t udp_broadcast_impl::recv(const boost::asio::mutable_buffer &buff){ - if (_socket->available() == 0) return 0; + reasonable_recv_timeout(*_socket); + if (not _socket->available()) return 0; boost::asio::ip::udp::endpoint sender_endpoint; return _socket->receive_from(boost::asio::buffer(buff), sender_endpoint); } |