[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8574 - in usrp2/trunk/host-ng: apps lib
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r8574 - in usrp2/trunk/host-ng: apps lib |
Date: |
Tue, 10 Jun 2008 15:24:51 -0600 (MDT) |
Author: jcorgan
Date: 2008-06-10 15:24:49 -0600 (Tue, 10 Jun 2008)
New Revision: 8574
Modified:
usrp2/trunk/host-ng/apps/test_eth.cc
usrp2/trunk/host-ng/lib/eth_buffer.cc
usrp2/trunk/host-ng/lib/eth_buffer.h
Log:
work-in-progress
Modified: usrp2/trunk/host-ng/apps/test_eth.cc
===================================================================
--- usrp2/trunk/host-ng/apps/test_eth.cc 2008-06-10 19:52:55 UTC (rev
8573)
+++ usrp2/trunk/host-ng/apps/test_eth.cc 2008-06-10 21:24:49 UTC (rev
8574)
@@ -40,7 +40,7 @@
int res;
do {
- res = buf.rx_frames(NULL, 0);
+ res = buf.rx_frames(NULL, 1000);
}
while (res != -1);
Modified: usrp2/trunk/host-ng/lib/eth_buffer.cc
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.cc 2008-06-10 19:52:55 UTC (rev
8573)
+++ usrp2/trunk/host-ng/lib/eth_buffer.cc 2008-06-10 21:24:49 UTC (rev
8574)
@@ -168,13 +168,12 @@
}
int
- eth_buffer::rx_frames(handler *f, int flags)
+ eth_buffer::rx_frames(handler *f, int timeout)
{
- if (ETH_BUFFER_DEBUG)
- DEBUG_LOG("'");
+ DEBUG_LOG("'");
while (!frame_available()) {
- if (flags & EF_DONTWAIT) {
+ if (timeout == 0) {
DEBUG_LOG("w");
return 0; // would block
}
@@ -186,20 +185,19 @@
DEBUG_LOG("P");
- int pres = poll(&pfd, 1, -1); // no timeout
- if (pres < 1) {
+ poll(&pfd, 1, timeout);
+ if (pfd.revents & POLLERR) {
+ perror("poll");
DEBUG_LOG("E");
- return -1;
+ return -1;
}
-
- if (pres == 0) {
+
+ if (!(pfd.revents & POLLIN)) {
DEBUG_LOG("T");
- continue;
+ return 2;
}
}
- DEBUG_LOG("r");
-
// Iterate through available packets
while (frame_available()) {
if (ETH_BUFFER_DEBUG)
Modified: usrp2/trunk/host-ng/lib/eth_buffer.h
===================================================================
--- usrp2/trunk/host-ng/lib/eth_buffer.h 2008-06-10 19:52:55 UTC (rev
8573)
+++ usrp2/trunk/host-ng/lib/eth_buffer.h 2008-06-10 21:24:49 UTC (rev
8574)
@@ -64,15 +64,15 @@
class handler {
public:
enum result {
- FREE_FRAME, // I'm done with the frame, please free it.
- KEEP_FRAME, // Hold onto the frame for the next call to rx_frames
+ KEEP = 0x0001, // retain frame for next rx_frames call
+ BREAK = 0x0010 // immediately return from rx_frames
};
-
+
/*!
* \param base points to the beginning of the frame (the 14-byte
ethernet header).
* \param len is the length in bytes of the frame.
*/
- virtual result operator()(const void *base, size_t len) = 0;
+ virtual result operator()(const uint8_t *base, size_t len) = 0;
virtual ~handler();
};
@@ -114,13 +114,26 @@
/*!
* \brief Call \p f for each frame in the receive buffer.
* \param f is the frame handler
- * \param flags is 0 or the bitwise-or of values from eth_flags
+ * \param timeout controls behavior when there are no frames to read
*
+ * If \p timeout is 0, rx_frames will not wait for frames if none are
+ * available, and f will not be invoked. If \p timeout is -1 (the
+ * default), rx_frames will block indefinitely until frames are
+ * available. If \p timeout is positive, it indicates the number of
+ * milliseconds to wait for a frame to become available. Once the
+ * timeout has expired, rx_frames will return, f never having been
+ * invoked.
+ *
* \p f will be called on each ethernet frame that is available.
- * \p f returns one of two values, FREE_FRAME, meaning I'm done
- * with the frame, or KEEP_FRAME, meaning hold onto the frame and
- * present it again on the next call to rx_frames.
+ * \p f returns a bit vector with one of the following set or cleared:
+ *
+ * handler::KEEP - hold onto the frame and present it again during the
+ * next call to rx_frames, otherwise discard it
*
+ * handler::BREAK - return from rx_frames even though more frames might
+ * be available, otherwise continue if more frames are
+ * ready
+ *
* The idea of holding onto a frame for the next iteration allows
* the caller to scan the received packet stream for particular
* classes of frames (such as command replies) leaving the rest
@@ -128,14 +141,12 @@
* frames received, will be presented in order to \p f.
* See usrp2.cc for an example of the pattern.
*
- * if \p flags contains EF_DONT_WAIT rx_frames will not wait for
- * frames if none are available, and f will not be invoked.
- *
- * \returns 0 if flags contains EF_DONT_WAIT and the call would have
blocked
- * \returns 1 if at least one frame was available
+ * \returns 0 if \p timeout is 0 and the call would have blocked
+ * \returns 1 if at least one frame was received
+ * \returns 2 if timeout occurred
* \returns -1 if there was an unrecoverable error.
*/
- int rx_frames(handler *f, int flags=0);
+ int rx_frames(handler *f, int timeout=-1);
/*
* \brief Write an ethernet frame to the interface.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8574 - in usrp2/trunk/host-ng: apps lib,
jcorgan <=