Discard data in gr_udp_sink until receiver is started.
authorDon Ward <don2387ward@sprynet.com>
Mon, 19 Apr 2010 21:02:14 +0000 (17:02 -0400)
committerDon Ward <don2387ward@sprynet.com>
Tue, 20 Apr 2010 14:37:59 +0000 (10:37 -0400)
Also fixes warnings from gcc 4.3 and adds <boost/bind.hpp> for usrp2.

gnuradio-core/src/lib/io/gr_udp_sink.cc
gnuradio-core/src/lib/io/gr_udp_source.cc
usrp2/host/include/usrp2/usrp2.h

index 3d8d65145b4078dcaf3d0c5a80d76b863b1231e8..b447dd3b3a89abb9cadb0a64b49f411df8b58477 100755 (executable)
@@ -36,7 +36,6 @@ typedef void* optval_t;
 #define USING_WINSOCK
 #define SHUT_RDWR 2
 typedef char* optval_t;
-#define ENOPROTOOPT 109
 #endif
 
 #include <gruel/thread.h>
@@ -47,6 +46,8 @@ static int is_error( int perr )
 {
   // Compare error to posix error code; return nonzero if match.
 #if defined(USING_WINSOCK)
+#define ENOPROTOOPT 109
+#define ECONNREFUSED 111
   // All codes to be checked for must be defined below
   int werr = WSAGetLastError();
   switch( werr ) {
@@ -54,6 +55,8 @@ static int is_error( int perr )
     return( perr == EAGAIN );
   case WSAENOPROTOOPT:
     return( perr == ENOPROTOOPT );
+  case WSAECONNREFUSED:
+    return( perr == ECONNREFUSED );
   default:
     fprintf(stderr,"gr_udp_source/is_error: unknown error %d\n", perr );
     throw std::runtime_error("internal error");
@@ -64,7 +67,7 @@ static int is_error( int perr )
 #endif
 }
 
-static void report_error( char *msg1, char *msg2 )
+static void report_error( const char *msg1, const char *msg2 )
 {
   // Deal with errors, both posix and winsock
 #if defined(USING_WINSOCK)
@@ -217,7 +220,7 @@ gr_udp_sink::work (int noutput_items,
   ssize_t total_size = noutput_items*d_itemsize;
 
   #if SNK_VERBOSE
-  printf("Entered upd_sink\n");
+  printf("Entered udp_sink\n");
   #endif
 
   while(bytes_sent <  total_size) {
@@ -225,8 +228,12 @@ gr_udp_sink::work (int noutput_items,
   
     r = send(d_socket, (in+bytes_sent), bytes_to_send, 0);
     if(r == -1) {         // error on send command
-      report_error("udp_sink",NULL); // there should be no error case where
-      return -1;                   // this function should not exit immediately
+      if( is_error(ECONNREFUSED) )
+       r = bytes_to_send;  // discard data until receiver is started
+      else {
+       report_error("udp_sink",NULL); // there should be no error case where
+       return -1;                  // this function should not exit immediately
+      }
     }
     bytes_sent += r;
     
index f459e7f1302fa7ba529fddf8248073953c814c51..56499258c3557e765a1ab50ca23a0f19ee76a20a 100755 (executable)
@@ -36,7 +36,6 @@ typedef void* optval_t;
 #define USING_WINSOCK
 #define SHUT_RDWR 2
 typedef char* optval_t;
-#define ENOPROTOOPT 109
 #endif
 
 #define SRC_VERBOSE 0
@@ -45,6 +44,7 @@ static int is_error( int perr )
 {
   // Compare error to posix error code; return nonzero if match.
 #if defined(USING_WINSOCK)
+#define ENOPROTOOPT 109
   // All codes to be checked for must be defined below
   int werr = WSAGetLastError();
   switch( werr ) {
index 7069507cfb593fde10563f1aed7d853374c39d9d..e29caa33db1bacb71132b415ac6b4ac235c96a15 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <boost/shared_ptr.hpp>
 #include <boost/utility.hpp>
+#include <boost/bind.hpp>
 #include <vector>
 #include <complex>
 #include <usrp2/rx_sample_handler.h>