commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r11034 - in gnuradio/branches/developers/eb/vrt/vrt: a


From: eb
Subject: [Commit-gnuradio] r11034 - in gnuradio/branches/developers/eb/vrt/vrt: apps lib
Date: Thu, 14 May 2009 19:12:51 -0600 (MDT)

Author: eb
Date: 2009-05-14 19:12:50 -0600 (Thu, 14 May 2009)
New Revision: 11034

Modified:
   gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc
   gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.cc
   gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.h
Log:
work-in-progress

Modified: gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc   
2009-05-14 22:49:13 UTC (rev 11033)
+++ gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc   
2009-05-15 01:12:50 UTC (rev 11034)
@@ -289,8 +289,7 @@
     bool ok = vrt_receiver->rx_packets(handler.get());
     if (!ok){
       fprintf(stderr, "vrt->rx_packets failed\n");
-      send_stop_rx_command(ctrl_fd);
-      return 1;
+      break;
     }
   }
 
@@ -299,5 +298,7 @@
   printf("%llu packets received, %llu bad pkt_cnt field values\n",
         handler->d_npackets, handler->d_nwrong_pkt_cnt);
 
+  sleep(3);
+
   return 0;
 }

Modified: gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.cc
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.cc     
2009-05-14 22:49:13 UTC (rev 11033)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.cc     
2009-05-15 01:12:50 UTC (rev 11034)
@@ -34,6 +34,7 @@
 #include <errno.h>
 #include <stdexcept>
 #include <string.h>
+#include <fcntl.h>
 
 
 #define SOCKET_RX_BUFFER_DEBUG      1 // define to 0 or 1
@@ -75,6 +76,43 @@
   bool 
   socket_rx_buffer::open()
   {
+    if (try_packet_ring()){
+      d_using_tpring = true;
+      fprintf(stderr, "socket_rx_buffer: using memory mapped interface\n");
+    }
+    else {
+      d_using_tpring = false;
+      fprintf(stderr, "socket_rx_buffer: NOT using memory mapped interface\n");
+
+      // Increase socket buffer if possible
+
+      int rcvbuf_size = d_buflen;
+#if defined(SO_RCVBUFFORCE)
+      if (setsockopt(d_fd, SOL_SOCKET, SO_RCVBUFFORCE, &rcvbuf_size, 
sizeof(rcvbuf_size)) != 0){
+       perror("setsockopt(SO_RCVBUFFORCE)");
+      }
+      else {
+       fprintf(stderr, "SO_RCVBUFFORCE = %zd\n", d_buflen);
+      }
+#endif
+
+      // put socket in non-blocking mode
+      int arg;
+      
+      if ((arg = fcntl(d_fd, F_GETFL, 0)) == -1){
+       perror("fcntl(F_GETFL)");
+      }
+      else if (fcntl(d_fd, F_SETFL, arg | O_NONBLOCK) == -1){
+       perror("fcntl(F_SETFL)");
+      }
+    }
+
+    return true;
+  }
+
+  bool
+  socket_rx_buffer::try_packet_ring()
+  {
     struct tpacket_req req;
     size_t page_size = getpagesize();
 
@@ -99,7 +137,7 @@
     req.tp_frame_nr = d_buflen/req.tp_frame_size;
     d_frame_nr = req.tp_frame_nr;
 
-#if 0
+#if 1
     if (SOCKET_RX_BUFFER_DEBUG)
       std::cerr << "socket_rx_buffer:" 
                << " frame_size=" << req.tp_frame_size
@@ -110,47 +148,30 @@
                << std::endl;
 #endif
 
-    // Try to get kernel shared memory buffer    
-    if (setsockopt(d_fd, SOL_PACKET, PACKET_RX_RING, (void *)&req, 
sizeof(req))) {
+    // Try to get kernel shared memory buffer
+    if (setsockopt(d_fd, SOL_PACKET, PACKET_RX_RING, (void *)&req, 
sizeof(req)) != 0){
       perror("socket_rx_buffer: setsockopt");
-      d_using_tpring = false;
-      if (!(d_buf = (uint8_t *)malloc(d_buflen))) {
-        std::cerr << "socket_rx_buffer: failed to allocate packet memory" << 
std::endl;
-       return false;
-      }
-      
-      std::cerr << "socket_rx_buffer: using malloc'd memory for buffer" << 
std::endl;
+      return false;
     }
-    else {
-      d_using_tpring = true;
-      void *p = mmap(0, d_buflen, PROT_READ|PROT_WRITE, MAP_SHARED, d_fd, 0);
-      if (p == MAP_FAILED){
-        perror("socket_rx_buffer: mmap");
-       return false;
-      }
-      d_buf = (uint8_t *) p;
 
-      if (SOCKET_RX_BUFFER_DEBUG)
-        std::cerr << "socket_rx_buffer: using kernel shared mem for buffer" << 
std::endl;
+    void *p = mmap(0, d_buflen, PROT_READ|PROT_WRITE, MAP_SHARED, d_fd, 0);
+    if (p == MAP_FAILED){
+      perror("socket_rx_buffer: mmap");
+      return false;
     }
+    d_buf = (uint8_t *) p;
 
     // 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.resize(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);
-    }
 
-    // If not using kernel ring, instantiate select/read thread here
-
     return true;
   }
 
   bool
   socket_rx_buffer::close()
   {
-    if (!d_using_tpring && d_buf)
-       free(d_buf);
-
     return true;
   }
 
@@ -163,6 +184,12 @@
   socket_rx_buffer::result
   socket_rx_buffer::rx_frames(data_handler *f, int timeout_in_ms)
   {
+    if (!d_using_tpring){
+      // FIXME
+      fprintf(stderr, "rx_frames: non-tpring not yet implemented\n");
+      return EB_ERROR;
+    }
+
     DEBUG_LOG("\n");
       
     while (!frame_available()) {

Modified: gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.h
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.h      
2009-05-14 22:49:13 UTC (rev 11033)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.h      
2009-05-15 01:12:50 UTC (rev 11034)
@@ -31,8 +31,7 @@
   class data_handler;
 
   /*!
-   * \brief high-performance interface to send and receive raw
-   * ethernet frames with out-of-order retirement of received frames.
+   * \brief high-performance interface to receive datagrams
    *
    * On many systems it should be possible to implement this on top of libpcap
    *
@@ -63,6 +62,7 @@
 
     bool open();
     bool close();
+    bool try_packet_ring();
 
   public:
 
@@ -114,7 +114,7 @@
     /*
      * \brief Returns maximum possible number of frames in buffer
      */
-    unsigned int max_frames() const { return d_frame_nr; }
+    unsigned int max_frames() const { return d_using_tpring ? d_frame_nr : 0; }
   };
 
 };  // namespace vrt





reply via email to

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