[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 49/148: Added read_packet with timeout meth
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 49/148: Added read_packet with timeout method to ethernet. Now the control recv can timeout and immediately recv. |
Date: |
Mon, 15 Aug 2016 00:47:23 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
nwest pushed a commit to annotated tag old_usrp_devel_udp
in repository gnuradio.
commit 93431af11a6a34bff8e8f05493cf955c1a9b4815
Author: Josh Blum <address@hidden>
Date: Fri Nov 20 19:16:40 2009 -0800
Added read_packet with timeout method to ethernet.
Now the control recv can timeout and immediately recv.
---
usrp2/host/lib/eth_ctrl_transport.cc | 16 ++++++++++------
usrp2/host/lib/eth_ctrl_transport.h | 10 +++++++---
usrp2/host/lib/ethernet.cc | 16 +++++++++++++++-
usrp2/host/lib/ethernet.h | 15 ++++++++++++++-
usrp2/host/lib/find.cc | 7 ++-----
usrp2/host/lib/transport.cc | 2 +-
6 files changed, 49 insertions(+), 17 deletions(-)
diff --git a/usrp2/host/lib/eth_ctrl_transport.cc
b/usrp2/host/lib/eth_ctrl_transport.cc
index 58fa58d..2a622cc 100644
--- a/usrp2/host/lib/eth_ctrl_transport.cc
+++ b/usrp2/host/lib/eth_ctrl_transport.cc
@@ -18,8 +18,8 @@
#include "eth_ctrl_transport.h"
-usrp2::eth_ctrl_transport::eth_ctrl_transport(const std::string &ifc,
u2_mac_addr_t mac, double timeout, bool target)
- : transport("ethernet control"), d_mac(mac), d_buff(NULL), d_timeout(timeout){
+usrp2::eth_ctrl_transport::eth_ctrl_transport(const std::string &ifc,
u2_mac_addr_t mac, bool target)
+ : transport("ethernet control"), d_mac(mac), d_buff(NULL){
//create raw ethernet device
d_eth_ctrl = new ethernet();
@@ -79,9 +79,15 @@ static void delete_array(uint8_t *array){delete[] array;}
usrp2::transport::sbuff_vec_t usrp2::eth_ctrl_transport::recv(){
sbuff_vec_t sbs;
for (size_t i = 0; i < max_buffs(); i++){
- //allocate a new buffer and recv
+ //conditionally allocate a new buffer
if (d_buff == NULL) d_buff = new uint8_t[ethernet::MAX_PKTLEN];
- int recv_len = d_eth_ctrl->read_packet_dont_block(d_buff,
ethernet::MAX_PKTLEN);
+ // This method must return immediately after getting a packet.
+ // Therefore, only the first call to read_packet (when size==0)
+ // may have a timeout and further calls must return immediately.
+ // This way, we return once all available packets have been read.
+ int recv_len = sbs.size()?
+ d_eth_ctrl->read_packet_dont_block(d_buff, ethernet::MAX_PKTLEN):
+ d_eth_ctrl->read_packet_timeout(d_buff, ethernet::MAX_PKTLEN,
100); // FIXME magic timeout
//strip the ethernet headers from the buffer
if (recv_len > (signed)sizeof(u2_eth_packet_t)){
sbs.push_back(sbuff::make(
@@ -91,7 +97,5 @@ usrp2::transport::sbuff_vec_t
usrp2::eth_ctrl_transport::recv(){
d_buff = NULL; //set to null to flag for a new allocation
} else break;
}
- //if nothing was received, busy sleep to save cpu
- if (sbs.size() == 0)
boost::this_thread::sleep(gruel::get_new_timeout(d_timeout));
return sbs;
}
diff --git a/usrp2/host/lib/eth_ctrl_transport.h
b/usrp2/host/lib/eth_ctrl_transport.h
index 3814cae..80fb10e 100644
--- a/usrp2/host/lib/eth_ctrl_transport.h
+++ b/usrp2/host/lib/eth_ctrl_transport.h
@@ -42,14 +42,18 @@ namespace usrp2{
* When the target is false, the packet filter is setup to ignore our
mac address.
* \param ifc the ethernet device name
* \param mac the destination mac address
- * \param timeout the timeout in seconds (default 50ms)
* \param target true for an inbound target
*/
- eth_ctrl_transport(const std::string &ifc, u2_mac_addr_t mac, double
timeout=0.05, bool target = true);
+ eth_ctrl_transport(const std::string &ifc, u2_mac_addr_t mac, bool
target = true);
~eth_ctrl_transport();
bool sendv(const iovec *iov, size_t iovlen);
sbuff_vec_t recv();
- size_t max_buffs(){return 3;}
+ /*!
+ * \brief Controls the maximum size returned by recv
+ * Any integer larger than 0 would work here.
+ * \return the max size of sbuffs recv vector
+ */
+ size_t max_buffs(){return 7;}
};
diff --git a/usrp2/host/lib/ethernet.cc b/usrp2/host/lib/ethernet.cc
index e51680b..9cbf291 100644
--- a/usrp2/host/lib/ethernet.cc
+++ b/usrp2/host/lib/ethernet.cc
@@ -37,6 +37,7 @@
#include <sys/socket.h>
#include <net/ethernet.h>
#include <netinet/in.h>
+#include <sys/poll.h>
#include <linux/types.h>
#include <netpacket/packet.h>
@@ -178,7 +179,20 @@ namespace usrp2 {
return len;
}
-
+
+ int
+ ethernet::read_packet_timeout (void *buf, int buflen, int timeout_in_ms)
+ {
+ struct pollfd pfd;
+ pfd.fd = d_fd;
+ pfd.revents = 0;
+ pfd.events = POLLIN;
+
+ poll(&pfd, 1, timeout_in_ms);
+
+ return read_packet_dont_block(buf, buflen);
+ }
+
int
ethernet::write_packet (const void *buf, int buflen)
{
diff --git a/usrp2/host/lib/ethernet.h b/usrp2/host/lib/ethernet.h
index 24624f4..7fcb0eb 100644
--- a/usrp2/host/lib/ethernet.h
+++ b/usrp2/host/lib/ethernet.h
@@ -92,7 +92,20 @@ namespace usrp2 {
* Returned packet includes 14-byte ethhdr
*/
int read_packet_dont_block (void *buf, int buflen);
-
+
+ /*!
+ * \brief Read packet from interface, but with timeout
+ *
+ * \param buf where to put the packet
+ * \param buflen maximum length of packet in bytes (should be >= 1528)
+ * \param timeout_in_ms the timeout in milliseconds
+ *
+ * \returns number of bytes read, -1 if trouble or 0 if nothing available.
+ *
+ * Returned packet includes 14-byte ethhdr
+ */
+ int read_packet_timeout (void *buf, int buflen, int timeout_in_ms);
+
/*
* \brief Write ethernet packet to interface.
*
diff --git a/usrp2/host/lib/find.cc b/usrp2/host/lib/find.cc
index a1c8a35..f8661d1 100644
--- a/usrp2/host/lib/find.cc
+++ b/usrp2/host/lib/find.cc
@@ -32,9 +32,6 @@
#define FIND_DEBUG false
-#define TRANSPORT_RECV_TIMEOUT 0.01 //10ms
-#define FIND_RESPONSE_TIMEOUT 0.05 //50ms
-
static const u2_mac_addr_t broadcast_mac_addr =
{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }};
@@ -49,7 +46,7 @@ namespace usrp2{
typedef boost::shared_ptr<find_helper> sptr;
find_helper(const std::string &ifc, const std::string &addr):
d_target_addr(addr){
- d_ctrl_transport = transport::sptr(new eth_ctrl_transport(ifc,
broadcast_mac_addr, TRANSPORT_RECV_TIMEOUT, false));
+ d_ctrl_transport = transport::sptr(new eth_ctrl_transport(ifc,
broadcast_mac_addr, false));
d_ctrl_transport->set_callback(boost::bind(&find_helper::handle_control_packet,
this, _1));
}
@@ -67,7 +64,7 @@ namespace usrp2{
d_ctrl_transport->sendv(&iov, 1);
//allow responses to gather
d_ctrl_transport->start();
-
boost::this_thread::sleep(gruel::get_new_timeout(FIND_RESPONSE_TIMEOUT));
+ boost::this_thread::sleep(gruel::get_new_timeout(0.05)); //50ms
d_ctrl_transport->stop();
return d_result;
}
diff --git a/usrp2/host/lib/transport.cc b/usrp2/host/lib/transport.cc
index b410f2a..028f892 100644
--- a/usrp2/host/lib/transport.cc
+++ b/usrp2/host/lib/transport.cc
@@ -61,7 +61,7 @@ void usrp2::transport::run(){
// call recv to get a new sbuffer
// pass the buffer into the callback
sbuff_vec_t sbs = recv();
- if (d_running and sbs.size()) d_cb(sbs);
+ if (sbs.size()) d_cb(sbs);
//catch thread interrupts, possibly from stop
//the running condition will be re-checked
}catch(boost::thread_interrupted const &){}
- [Commit-gnuradio] [gnuradio] 26/148: moved regs around for vita49, (continued)
- [Commit-gnuradio] [gnuradio] 26/148: moved regs around for vita49, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 19/148: VITA49 rx (and tx skeleton) copied over from quad radio, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 43/148: minor tweak to transport loop and debug printf for vrt, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 44/148: Removed temporary u2_eth_packet_only_t. Removed the fixed header portion from the u2_eth_packet_t. Removed places in code where control uses the fixed header (always unused 0 for word, and -1 for timestamp). Flagged the fixed header stuff for removal (once we get vrt tx)., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 25/148: cleanup, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 42/148: Created a ring data structure held by the ring. It holds an sbuff and its parsed vrt data (header, payload, and len). The impl data handler parses the packets and enqueues them., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 48/148: Added interrupt call from transport::stop so the recv or callback will throw at interruption points. This fixes the issue where the app would hang in the stop method when exiting (we were hanging here: d_data_pending_cond.wait(l), but now wait throws() and we exit)., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 54/148: flag packets which arrive way too early so the device doesn't sit there forever., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 38/148: rx working with vrt header, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 45/148: Re-implemented find.cc with gruel and eth_ctrl_transport class. Added constructor args to the eth control transport to set the timeout and target for the packet filter., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 49/148: Added read_packet with timeout method to ethernet. Now the control recv can timeout and immediately recv.,
git <=
- [Commit-gnuradio] [gnuradio] 21/148: put 64 bit timer for vita49 on the settings bus, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 47/148: Handled the case of short packets in eth data transport by using padding., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 70/148: changed debug pins to see incoming data, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 51/148: progress on vita_tx. it compiles now, need to work on vita_tx_control., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 46/148: Created and used a typedef for a vector of sbuffs. Changed the return type for the transport sendv to bool. Not all transports can return the number of bytes sent, and we only care if the transport succeeded or not. This fixes an issue of the usrp2 impl freezing on close after tx, because the return value from sednv was improperly handled., git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 66/148: Merge branch 'vita_rx' of http://gnuradio.org/git/matt into wip/usrp2, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 79/148: cleaned up the main ibs state machine, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 71/148: Merge branch 'vita_rx' of gnuradio.org:matt into vita_rx, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 53/148: very basic packet sending works, git, 2016/08/14
- [Commit-gnuradio] [gnuradio] 77/148: Merge branch 'master' of gnuradio.org:gnuradio into vita_rx, git, 2016/08/14