Ignore ENOPROTOOPT return from setsockopt(SO_LINGER)
authorDon Ward <don2387ward@sprynet.com>
Thu, 15 Apr 2010 18:37:04 +0000 (14:37 -0400)
committerDon Ward <don2387ward@sprynet.com>
Thu, 15 Apr 2010 18:37:04 +0000 (14:37 -0400)
SO_LINGER is not valid for SOCK_DGRAM sockets on Windows, so we
expect setsockopt to return ENOPROTOOPT (invalid option for
protocol) on Cygwin and MinGW.  If it happens on any other system
it should probably be ignored there, too.

gnuradio-core/src/lib/io/gr_udp_sink.cc [changed mode: 0644->0755]
gnuradio-core/src/lib/io/gr_udp_source.cc [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index d37adfb..a837e73
@@ -132,8 +132,10 @@ gr_udp_sink::open()
   lngr.l_onoff  = 1;
   lngr.l_linger = 0;
   if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (optval_t)&lngr, sizeof(linger)) == -1) {
-    perror("SO_LINGER");
-    throw std::runtime_error("can't set socket option SO_LINGER");
+    if(errno != ENOPROTOOPT) {  // no SO_LINGER for SOCK_DGRAM on Windows
+      perror("SO_LINGER");
+      throw std::runtime_error("can't set socket option SO_LINGER");
+    }
   }
 
   // bind socket to an address and port number to listen on
old mode 100644 (file)
new mode 100755 (executable)
index d76d0ee..fed5b61
@@ -110,8 +110,10 @@ gr_udp_source::open()
   lngr.l_onoff  = 1;
   lngr.l_linger = 0;
   if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (optval_t)&lngr, sizeof(linger)) == -1) {
-    perror("SO_LINGER");
-    throw std::runtime_error("can't set socket option SO_LINGER");
+    if(errno != ENOPROTOOPT) {  // no SO_LINGER for SOCK_DGRAM on Windows
+      perror("SO_LINGER");
+      throw std::runtime_error("can't set socket option SO_LINGER");
+    }
   }
 
   // Set a timeout on the receive function to not block indefinitely