commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: eb
Subject: [Commit-gnuradio] r11035 - in gnuradio/branches/developers/eb/vrt/vrt: apps lib
Date: Thu, 14 May 2009 21:08:38 -0600 (MDT)

Author: eb
Date: 2009-05-14 21:08:38 -0600 (Thu, 14 May 2009)
New Revision: 11035

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

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-15 01:12:50 UTC (rev 11034)
+++ gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc   
2009-05-15 03:08:38 UTC (rev 11035)
@@ -283,7 +283,7 @@
   // start receiving packets
 
   uint64_t     niter = 0;
-  uint64_t     max_iter = 1000000;
+  uint64_t     max_iter = 1000;
 
   while(!signaled && niter++ < max_iter){
     bool ok = vrt_receiver->rx_packets(handler.get());

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-15 01:12:50 UTC (rev 11034)
+++ gnuradio/branches/developers/eb/vrt/vrt/lib/socket_rx_buffer.cc     
2009-05-15 03:08:38 UTC (rev 11035)
@@ -95,16 +95,6 @@
        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;
@@ -185,11 +175,52 @@
   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;
+
+      // ----------------------------------------------------------------
+      // Use recv instead of kernel Rx packet ring
+      // ----------------------------------------------------------------
+
+      unsigned char buf[MAX_PKTLEN];
+      bool dont_wait = timeout_in_ms == 0;     // FIXME treating timeout as 0 
or inf
+      int flags = dont_wait ? MSG_DONTWAIT : 0;
+
+      ssize_t rr = recv(d_fd, buf, sizeof(buf), flags);
+      if (rr == -1){           // error?
+       if (errno == EAGAIN){   // non-blocking, nothing there
+         return EB_WOULD_BLOCK;
+       }
+       perror("rx_frames: recv");
+       return EB_ERROR;
+      }
+
+      // Got first packet.  Call handler
+
+      data_handler::result r = (*f)(buf, rr);
+      if (r & data_handler::DONE)
+       return EB_OK;
+
+      // Now do as many as we can without blocking
+
+      while (1){
+       rr = recv(d_fd, buf, sizeof(buf), MSG_DONTWAIT);
+       if (rr == -1){          // error?
+         if (errno == EAGAIN)  // non-blocking, nothing there
+           return EB_OK;       // return OK; we've processed >= 1 packets
+         perror("rx_frames: recv");
+         return EB_ERROR;
+       }
+       
+       r = (*f)(buf, rr);
+       if (r & data_handler::DONE)
+         break;
+      }
+      return EB_OK;
     }
 
+    // ----------------------------------------------------------------
+    // Use kernel Rx packet ring
+    // ----------------------------------------------------------------
+
     DEBUG_LOG("\n");
       
     while (!frame_available()) {





reply via email to

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