commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 48/148: Added interrupt call from transport


From: git
Subject: [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).
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 3628a061c6040238af29a1217cfcbbd7e693dae0
Author: Josh Blum <address@hidden>
Date:   Fri Nov 20 16:07:58 2009 -0800

    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).
    
    Also, setup padding in the eth data/control transport so its only allocated 
and zeroed at init.
---
 usrp2/host/lib/eth_ctrl_transport.cc |  6 +++---
 usrp2/host/lib/eth_ctrl_transport.h  |  1 +
 usrp2/host/lib/eth_data_transport.cc | 11 ++++++++---
 usrp2/host/lib/eth_data_transport.h  |  1 +
 usrp2/host/lib/transport.cc          |  3 ++-
 5 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/usrp2/host/lib/eth_ctrl_transport.cc 
b/usrp2/host/lib/eth_ctrl_transport.cc
index 8f7c418..58fa58d 100644
--- a/usrp2/host/lib/eth_ctrl_transport.cc
+++ b/usrp2/host/lib/eth_ctrl_transport.cc
@@ -31,6 +31,8 @@ usrp2::eth_ctrl_transport::eth_ctrl_transport(const 
std::string &ifc, u2_mac_add
     else        d_pf_ctrl = 
pktfilter::make_ethertype_inbound(U2_CTRL_ETHERTYPE, d_eth_ctrl->mac());
     if (!d_pf_ctrl || !d_eth_ctrl->attach_pktfilter(d_pf_ctrl))
         throw std::runtime_error("Unable to attach packet filter for control 
packets.");
+
+    memset(d_padding, 0, sizeof(d_padding));
 }
 
 usrp2::eth_ctrl_transport::~eth_ctrl_transport(){
@@ -65,9 +67,7 @@ bool usrp2::eth_ctrl_transport::sendv(const iovec *iov, 
size_t iovlen){
         num_bytes += all_iov[i].iov_len;
     }
     //handle padding, must be at least minimum length
-    uint8_t padding[ethernet::MIN_PKTLEN];
-    memset(padding, 0, ethernet::MIN_PKTLEN);
-    all_iov[all_iov_len-1].iov_base = padding;
+    all_iov[all_iov_len-1].iov_base = d_padding;
     all_iov[all_iov_len-1].iov_len = 
std::max(int(ethernet::MIN_PKTLEN)-num_bytes, 0);
     return d_eth_ctrl->write_packetv(all_iov, all_iov_len) > 0;
 }
diff --git a/usrp2/host/lib/eth_ctrl_transport.h 
b/usrp2/host/lib/eth_ctrl_transport.h
index 346fbc2..3814cae 100644
--- a/usrp2/host/lib/eth_ctrl_transport.h
+++ b/usrp2/host/lib/eth_ctrl_transport.h
@@ -33,6 +33,7 @@ namespace usrp2{
         u2_mac_addr_t d_mac;
         uint8_t       *d_buff;
         double_t      d_timeout;
+        uint8_t       d_padding[ethernet::MIN_PKTLEN];
 
     public:
         /*!
diff --git a/usrp2/host/lib/eth_data_transport.cc 
b/usrp2/host/lib/eth_data_transport.cc
index 88e7b4f..7f556e6 100644
--- a/usrp2/host/lib/eth_data_transport.cc
+++ b/usrp2/host/lib/eth_data_transport.cc
@@ -35,6 +35,8 @@ usrp2::eth_data_transport::eth_data_transport(const 
std::string &ifc, u2_mac_add
     d_pf_data = pktfilter::make_ethertype_inbound_target(U2_DATA_ETHERTYPE, 
(const unsigned char*)&(d_mac.addr));
     if (!d_pf_data || !d_eth_data->attach_pktfilter(d_pf_data))
         throw std::runtime_error("Unable to attach packet filter for data 
packets.");
+
+    memset(d_padding, 0, sizeof(d_padding));
 }
 
 usrp2::eth_data_transport::~eth_data_transport(){
@@ -73,9 +75,7 @@ bool usrp2::eth_data_transport::sendv(const iovec *iov, 
size_t iovlen){
         num_bytes += all_iov[i].iov_len;
     }
     //handle padding, must be at least minimum length
-    uint8_t padding[eth_buffer::MIN_PKTLEN];
-    memset(padding, 0, eth_buffer::MIN_PKTLEN);
-    all_iov[all_iov_len-1].iov_base = padding;
+    all_iov[all_iov_len-1].iov_base = d_padding;
     all_iov[all_iov_len-1].iov_len = 
std::max(int(eth_buffer::MIN_PKTLEN)-num_bytes, 0);
     return (d_eth_data->tx_framev(all_iov, all_iov_len) == eth_buffer::EB_OK)? 
true : false;
 }
@@ -91,6 +91,11 @@ usrp2::transport::sbuff_vec_t 
usrp2::eth_data_transport::recv(){
         void *base = iovs[i].iov_base;
         size_t len = iovs[i].iov_len;
 
+        if (len <= sizeof(u2_eth_packet_t)){
+            DEBUG_LOG("D");
+            continue; //drop truncated packet
+        }
+
         u2_eth_packet_t *hdr = (u2_eth_packet_t *)base;
         d_num_rx_frames++;
         d_num_rx_bytes += len;
diff --git a/usrp2/host/lib/eth_data_transport.h 
b/usrp2/host/lib/eth_data_transport.h
index 936c717..4955327 100644
--- a/usrp2/host/lib/eth_data_transport.h
+++ b/usrp2/host/lib/eth_data_transport.h
@@ -39,6 +39,7 @@ namespace usrp2{
         unsigned int   d_num_rx_missing;
         unsigned int   d_num_rx_overruns;
         unsigned int   d_num_rx_bytes;
+        uint8_t        d_padding[eth_buffer::MIN_PKTLEN];
 
     public:
         eth_data_transport(const std::string &ifc, u2_mac_addr_t mac, size_t 
rx_bufsize);
diff --git a/usrp2/host/lib/transport.cc b/usrp2/host/lib/transport.cc
index 2f94fd6..b410f2a 100644
--- a/usrp2/host/lib/transport.cc
+++ b/usrp2/host/lib/transport.cc
@@ -50,6 +50,7 @@ void usrp2::transport::stop(){
         throw std::runtime_error("usrp2::transport for " + d_type_str + " 
already stopped\n");
     }
     d_running = false;
+    d_thread->interrupt();
     d_thread->join();
 }
 
@@ -61,7 +62,7 @@ void usrp2::transport::run(){
             // pass the buffer into the callback
             sbuff_vec_t sbs = recv();
             if (d_running and sbs.size()) d_cb(sbs);
-        //catch thread interrupts from join, sleep, etc
+        //catch thread interrupts, possibly from stop
         //the running condition will be re-checked
         }catch(boost::thread_interrupted const &){}
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]