[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9024 - usrp2/branches/features/host-ng/host-ng/lib
From: |
eb |
Subject: |
[Commit-gnuradio] r9024 - usrp2/branches/features/host-ng/host-ng/lib |
Date: |
Fri, 25 Jul 2008 18:44:08 -0600 (MDT) |
Author: eb
Date: 2008-07-25 18:44:08 -0600 (Fri, 25 Jul 2008)
New Revision: 9024
Modified:
usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.cc
usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.h
usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc
Log:
removed magic numbers
Modified: usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.cc 2008-07-25
23:13:41 UTC (rev 9023)
+++ usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.cc 2008-07-26
00:44:08 UTC (rev 9024)
@@ -33,7 +33,9 @@
#include <iostream>
#include <cmath>
#include <errno.h>
+#include <stdexcept>
+
#define ETH_BUFFER_DEBUG 0 // define to 0 or 1
#if ETH_BUFFER_DEBUG
#define DEBUG_LOG(x) ::write(2, (x), 1)
@@ -135,12 +137,10 @@
std::cerr << "eth_buffer: using kernel shared mem for buffer" <<
std::endl;
}
- // Initialize packet ring
+ // Initialize our pointers into the packet ring
d_ring = std::vector<uint8_t *>(req.tp_frame_nr);
for (unsigned int i=0; i < req.tp_frame_nr; i++) {
d_ring[i] = (uint8_t *)(d_buf+i*req.tp_frame_size);
- // ((tpacket_hdr *)(d_ring[i]))->tp_status = TP_STATUS_KERNEL; // free
- // ((tpacket_hdr *)(d_ring[i]))->tp_len = req.tp_frame_size;
}
// If not using kernel ring, instantiate select/read thread here
@@ -171,7 +171,7 @@
return (((tpacket_hdr *)d_ring[d_head])->tp_status != TP_STATUS_KERNEL);
}
- int
+ eth_buffer::result
eth_buffer::rx_frames(data_handler *f, int timeout_in_ms)
{
DEBUG_LOG("\n");
@@ -179,7 +179,7 @@
while (!frame_available()) {
if (timeout_in_ms == 0) {
DEBUG_LOG("w");
- return 0; // would block
+ return EB_WOULD_BLOCK;
}
struct pollfd pfd;
@@ -192,12 +192,12 @@
int pres = poll(&pfd, 1, timeout_in_ms);
if (pres == -1) {
perror("poll");
- return -1;
+ return EB_ERROR;
}
if (pres == 0) {
DEBUG_LOG("t");
- return 2;
+ return EB_TIMED_OUT;
}
}
@@ -210,9 +210,8 @@
// Invoke data handler
data_handler::result r = (*f)(base, len);
- if (!(r & data_handler::KEEP)) {
+ if (!(r & data_handler::KEEP))
hdr->tp_status = TP_STATUS_KERNEL; // mark it free
- }
inc_head();
@@ -221,20 +220,22 @@
}
DEBUG_LOG("|");
- return 1;
+ return EB_OK;
}
- int
+ eth_buffer::result
eth_buffer::tx_frame(const void *base, size_t len, int flags)
{
- // TODO: implement flags
DEBUG_LOG("T");
+
+ if (flags & EF_DONTWAIT) // FIXME: implement flags
+ throw std::runtime_error("tx_frame: EF_DONTWAIT not implemented");
+
int res = d_ethernet->write_packet(base, len);
-
if (res < 0 || (unsigned int)res != len)
- return -1;
+ return EB_ERROR;
- return 1;
+ return EB_OK;
}
void
Modified: usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.h
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.h 2008-07-25
23:13:41 UTC (rev 9023)
+++ usrp2/branches/features/host-ng/host-ng/lib/eth_buffer.h 2008-07-26
00:44:08 UTC (rev 9024)
@@ -68,6 +68,13 @@
public:
+ enum result {
+ EB_OK, //< everything's fine
+ EB_ERROR, //< A non-recoverable error occurred
+ EB_WOULD_BLOCK, //< A timeout of 0 was specified and nothing was ready
+ EB_TIMED_OUT, //< The timeout expired before anything was ready
+ };
+
static const unsigned int MAX_PKTLEN = 1512;
static const unsigned int MIN_PKTLEN = 64;
@@ -133,12 +140,12 @@
* frames received, will be presented in order to \p f.
* See usrp2.cc for an example of the pattern.
*
- * \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.
+ * \returns EB_OK if at least one frame was received
+ * \returns EB_WOULD_BLOCK if \p timeout is 0 and the call would have
blocked
+ * \returns EB_TIMED_OUT if timeout occurred
+ * \returns EB_ERROR if there was an unrecoverable error.
*/
- int rx_frames(data_handler *f, int timeout=-1);
+ result rx_frames(data_handler *f, int timeout=-1);
/*
* \brief Release frame from buffer
@@ -148,7 +155,6 @@
*/
void release_frame(void *p);
-
/*
* \brief Write an ethernet frame to the interface.
*
@@ -158,11 +164,11 @@
*
* The frame must begin with a 14-byte ethernet header.
*
- * \returns 0 if flags contains EF_DONT_WAIT and the call would have
blocked
- * \returns 1 if the frame was successfully enqueued.
- * \returns -1 if there was an unrecoverable error.
+ * \returns EB_OK if the frame was successfully enqueued.
+ * \returns EB_WOULD_BLOCK if flags contains EF_DONT_WAIT and the call
would have blocked.
+ * \returns EB_ERROR if there was an unrecoverable error.
*/
- int tx_frame(const void *base, size_t len, int flags=0);
+ result tx_frame(const void *base, size_t len, int flags=0);
/*
* \brief Write an ethernet frame to the interface using scatter/gather.
@@ -173,11 +179,11 @@
*
* The frame must begin with a 14-byte ethernet header.
*
- * \returns 0 if flags contains EF_DONT_WAIT and the call would have
blocked
- * \returns 1 if the frame was successfully enqueued.
- * \returns -1 if there was an unrecoverable error.
+ * \returns EB_OK if the frame was successfully enqueued.
+ * \returns EB_WOULD_BLOCK if flags contains EF_DONT_WAIT and the call
would have blocked.
+ * \returns EB_ERROR if there was an unrecoverable error.
*/
- int tx_framev(const eth_iovec *iov, int iovcnt, int flags=0);
+ result tx_framev(const eth_iovec *iov, int iovcnt, int flags=0);
/*
* \brief Returns maximum possible number of frames in buffer
Modified: usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc 2008-07-25
23:13:41 UTC (rev 9023)
+++ usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc 2008-07-26
00:44:08 UTC (rev 9024)
@@ -377,7 +377,7 @@
d_pending_replies[p->rid()] = p;
// Transmit command
- if (d_eth_buf->tx_frame(cmd, len) != 1) {
+ if (d_eth_buf->tx_frame(cmd, len) != eth_buffer::EB_OK) {
d_pending_replies[p->rid()] = 0;
return false;
}
@@ -400,7 +400,7 @@
// process control frames, enqueue data packets in channel
// rings, and signal blocked API threads
int res = d_eth_buf->rx_frames(this, 100); // FIXME magic timeout
- if (res == -1)
+ if (res == eth_buffer::EB_ERROR)
break;
// Wait for user API thread(s) to process all enqueued packets.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9024 - usrp2/branches/features/host-ng/host-ng/lib,
eb <=