aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/transport/udp_common.hpp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-02-20 01:13:03 -0800
committerJosh Blum <josh@joshknows.com>2011-02-20 01:13:03 -0800
commit2d9838f467013d5397b6daf83afb5ccea92065a4 (patch)
treecc34b6106523307a2f18eff86c3311f3458d9eb7 /host/lib/transport/udp_common.hpp
parent8ab02dbef4cb36b2419371c131ff8c8edae88ce8 (diff)
downloaduhd-2d9838f467013d5397b6daf83afb5ccea92065a4.tar.gz
uhd-2d9838f467013d5397b6daf83afb5ccea92065a4.tar.bz2
uhd-2d9838f467013d5397b6daf83afb5ccea92065a4.zip
udp: update docs for transport, create common header for wait implementation
Reimplemented simple udp transport with one impl class. Moved wait for ready/select implementation into common header. Important note on select, timeval should have usecs < 1 second or it may error on some platforms. Fixed in this implementation.
Diffstat (limited to 'host/lib/transport/udp_common.hpp')
-rw-r--r--host/lib/transport/udp_common.hpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/host/lib/transport/udp_common.hpp b/host/lib/transport/udp_common.hpp
new file mode 100644
index 000000000..44067b5dc
--- /dev/null
+++ b/host/lib/transport/udp_common.hpp
@@ -0,0 +1,51 @@
+//
+// Copyright 2011 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_LIBUHD_TRANSPORT_VRT_PACKET_HANDLER_HPP
+#define INCLUDED_LIBUHD_TRANSPORT_VRT_PACKET_HANDLER_HPP
+
+#include <uhd/config.hpp>
+#include <boost/asio.hpp>
+
+namespace uhd{ namespace transport{
+
+ /*!
+ * Wait for the socket to become ready for a receive operation.
+ * \param sock_fd the open socket file descriptor
+ * \param timeout the timeout duration in seconds
+ * \return true when the socket is ready for receive
+ */
+ UHD_INLINE bool wait_for_recv(int sock_fd, double timeout){
+ //setup timeval for timeout
+ timeval tv;
+ //If the tv_usec > 1 second on some platforms, select will
+ //error EINVAL: An invalid timeout interval was specified.
+ tv.tv_sec = int(timeout);
+ tv.tv_usec = int(timeout*1000000)%1000000;
+
+ //setup rset for timeout
+ fd_set rset;
+ FD_ZERO(&rset);
+ FD_SET(sock_fd, &rset);
+
+ //call select with timeout on receive socket
+ return ::select(sock_fd+1, &rset, NULL, NULL, &tv) > 0;
+ }
+
+}} //namespace uhd::transport
+
+#endif /* INCLUDED_LIBUHD_TRANSPORT_VRT_PACKET_HANDLER_HPP */