Added git ignore files auto created from svn:ignore properties.
[debian/gnuradio] / gnuradio-core / src / lib / io / gr_udp_source.cc
index f7f04d3cf9384b930bbbd74d16b2a4da90ad0c97..d76d0ee32fcd5ef5ab21d2b4a2ab5373d4485f46 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2007,2008 Free Software Foundation, Inc.
+ * Copyright 2007,2008,2009 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
 #include <gr_io_signature.h>
 #include <stdexcept>
 #include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#if defined(HAVE_SOCKET)
 #include <netdb.h>
+typedef void* optval_t;
+#else
+#define SHUT_RDWR 2
+#define inet_aton(N,A) ( (A)->s_addr = inet_addr(N), ( (A)->s_addr != INADDR_NONE ) )
+typedef char* optval_t;
+#endif
 
 #define SRC_VERBOSE 0
 
@@ -81,7 +90,7 @@ gr_udp_source::~gr_udp_source ()
 bool
 gr_udp_source::open()
 {
-  omni_mutex_lock l(d_mutex);  // hold mutex for duration of this function
+  gruel::scoped_lock guard(d_mutex);   // hold mutex for duration of this function
   // create socket
   d_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
   if(d_socket == -1) {
@@ -91,7 +100,7 @@ gr_udp_source::open()
 
   // Turn on reuse address
   int opt_val = 1;
-  if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int)) == -1) {
+  if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (optval_t)&opt_val, sizeof(int)) == -1) {
     perror("SO_REUSEADDR");
     throw std::runtime_error("can't set socket option SO_REUSEADDR");
   }
@@ -100,7 +109,7 @@ gr_udp_source::open()
   linger lngr;
   lngr.l_onoff  = 1;
   lngr.l_linger = 0;
-  if(setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (void*)&lngr, sizeof(linger)) == -1) {
+  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");
   }
@@ -110,7 +119,7 @@ gr_udp_source::open()
   timeval timeout;
   timeout.tv_sec = 1;
   timeout.tv_usec = 0;
-  if(setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (void*)&timeout, sizeof(timeout)) == -1) {
+  if(setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (optval_t)&timeout, sizeof(timeout)) == -1) {
     perror("SO_RCVTIMEO");
     throw std::runtime_error("can't set socket option SO_RCVTIMEO");
   }
@@ -128,7 +137,7 @@ gr_udp_source::open()
 void
 gr_udp_source::close()
 {
-  omni_mutex_lock l(d_mutex);  // hold mutex for duration of this function
+  gruel::scoped_lock guard(d_mutex);   // hold mutex for duration of this function
 
   if (d_socket){
     shutdown(d_socket, SHUT_RDWR);