/* -*- 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
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) {
// 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");
}
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");
}
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");
}
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);