From b4b80f1f6e59fa02d508af860f1a572c9224b975 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 15 Jun 2010 01:23:00 +0000 Subject: usrp-e: added poll(...) call before read(...) call --- host/lib/usrp/usrp_e/io_impl.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'host/lib') 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 //read, write #include //transfer frame struct #include //offsetof +#include #include #include @@ -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(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(buff)->len; boost::uint32_t *vrt_header = boost::asio::buffer_cast(buff) + vrt_header_offset_words32; -- cgit v1.2.3