diff options
author | Josh Blum <josh@joshknows.com> | 2010-06-15 01:23:00 +0000 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-06-15 01:23:00 +0000 |
commit | b4b80f1f6e59fa02d508af860f1a572c9224b975 (patch) | |
tree | 0cf243fae752f12549fe437ad5c197c9be0509ca /host | |
parent | 6d43a4e83814c5c325caefb35eb1e07b415d8d37 (diff) | |
download | uhd-b4b80f1f6e59fa02d508af860f1a572c9224b975.tar.gz uhd-b4b80f1f6e59fa02d508af860f1a572c9224b975.tar.bz2 uhd-b4b80f1f6e59fa02d508af860f1a572c9224b975.zip |
usrp-e: added poll(...) call before read(...) call
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/usrp/usrp_e/io_impl.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/host/lib/usrp/usrp_e/io_impl.cpp b/host/lib/usrp/usrp_e/io_impl.cpp index e1c1fe80b..829e923b5 100644 --- a/host/lib/usrp/usrp_e/io_impl.cpp +++ b/host/lib/usrp/usrp_e/io_impl.cpp @@ -22,6 +22,7 @@ #include <fcntl.h> //read, write #include <linux/usrp_e.h> //transfer frame struct #include <stddef.h> //offsetof +#include <poll.h> #include <boost/format.hpp> #include <iostream> @@ -75,12 +76,22 @@ private: //std::cout << boost::format( // "calling read on fd %d, buff size is %d" //) % _fd % boost::asio::buffer_size(buff) << std::endl; + + //setup and call poll on the file descriptor + //return 0 and do not read when poll times out + pollfd pfd; + pfd.fd = _fd; + pfd.events = POLLIN; + if (poll(&pfd, 1, 100 /*ms*/) <= 0) return 0; //timeout + + //perform the blocking read(...) ssize_t ret = read( _fd, boost::asio::buffer_cast<void *>(buff), boost::asio::buffer_size(buff) ); if (ret < ssize_t(sizeof(usrp_transfer_frame))) return 0; + //overwrite the vrt header length with the transfer frame length size_t frame_size = boost::asio::buffer_cast<usrp_transfer_frame *>(buff)->len; boost::uint32_t *vrt_header = boost::asio::buffer_cast<boost::uint32_t *>(buff) + vrt_header_offset_words32; |