summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib/io
diff options
context:
space:
mode:
authorDon Ward2010-05-04 12:41:52 -0400
committerDon Ward2010-05-04 12:41:52 -0400
commitd702e27d1f3b0e76ef3734ee6b5b6ac1333cdbff (patch)
tree40568ebdb838ba9222068433548070399c2e277e /gnuradio-core/src/lib/io
parentdda6ed353551d3493983bd56e0ca8ee8ed4407c5 (diff)
downloadgnuradio-d702e27d1f3b0e76ef3734ee6b5b6ac1333cdbff.tar.gz
gnuradio-d702e27d1f3b0e76ef3734ee6b5b6ac1333cdbff.tar.bz2
gnuradio-d702e27d1f3b0e76ef3734ee6b5b6ac1333cdbff.zip
Rework UDP source and sink, with incompatible API changes
Remove source address specifications for sink; add connect() and disconnect() to sink; add get_port() to source; add optional EOF signaling (using zero-length packets) to sink and source; modify dial_tone, vector, and audio examples to match new code; add qa test case.
Diffstat (limited to 'gnuradio-core/src/lib/io')
-rwxr-xr-xgnuradio-core/src/lib/io/gr_udp_sink.cc161
-rwxr-xr-x[-rw-r--r--]gnuradio-core/src/lib/io/gr_udp_sink.h72
-rwxr-xr-x[-rw-r--r--]gnuradio-core/src/lib/io/gr_udp_sink.i21
-rwxr-xr-xgnuradio-core/src/lib/io/gr_udp_source.cc62
-rwxr-xr-xgnuradio-core/src/lib/io/gr_udp_source.h70
-rwxr-xr-xgnuradio-core/src/lib/io/gr_udp_source.i14
6 files changed, 243 insertions, 157 deletions
diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc
index 263d3dd4f..a9cb87a21 100755
--- a/gnuradio-core/src/lib/io/gr_udp_sink.cc
+++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc
@@ -30,6 +30,8 @@
#include <stdio.h>
#include <string.h>
#if defined(HAVE_NETDB_H)
+#include <netdb.h>
+#include <sys/socket.h> //usually included by <netdb.h>?
typedef void* optval_t;
#elif defined(HAVE_WINDOWS_H)
// if not posix, assume winsock
@@ -84,18 +86,14 @@ static void report_error( const char *msg1, const char *msg2 )
}
gr_udp_sink::gr_udp_sink (size_t itemsize,
- const char *src, unsigned short port_src,
- const char *dst, unsigned short port_dst,
- int payload_size)
+ const char *host, unsigned short port,
+ int payload_size, bool eof)
: gr_sync_block ("udp_sink",
gr_make_io_signature (1, 1, itemsize),
gr_make_io_signature (0, 0, 0)),
- d_itemsize (itemsize), d_payload_size(payload_size)
+ d_itemsize (itemsize), d_payload_size(payload_size), d_eof(eof),
+ d_connected(false)
{
- int ret = 0;
- struct addrinfo *ip_src; // store the source ip info
- struct addrinfo *ip_dst; // store the destination ip info
-
#if defined(USING_WINSOCK) // for Windows (with MinGW)
// initialize winsock DLL
WSADATA wsaData;
@@ -104,41 +102,13 @@ gr_udp_sink::gr_udp_sink (size_t itemsize,
report_error( "gr_udp_source WSAStartup", "can't open socket" );
}
#endif
-
- // Set up the address stucture for the source address and port numbers
- // Get the source IP address from the host name
- struct addrinfo hints;
- memset( (void*)&hints, 0, sizeof(hints) );
- hints.ai_family = AF_INET;
- hints.ai_socktype = SOCK_DGRAM;
- hints.ai_protocol = IPPROTO_UDP;
- char port_str[7];
- sprintf( port_str, "%d", port_src );
- ret = getaddrinfo( src, port_str, &hints, &ip_src );
- if( ret != 0 )
- report_error("gr_udp_source/getaddrinfo",
- "can't initialize source socket" );
-
- // Get the destination IP address from the host name
- sprintf( port_str, "%d", port_dst );
- ret = getaddrinfo( dst, port_str, &hints, &ip_dst );
- if( ret != 0 )
- report_error("gr_udp_source/getaddrinfo",
- "can't initialize destination socket" );
// create socket
- d_socket = socket(ip_src->ai_family, ip_src->ai_socktype,
- ip_src->ai_protocol);
+ d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(d_socket == -1) {
report_error("socket open","can't open socket");
}
- // Turn on reuse address
- int opt_val = true;
- if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (optval_t)&opt_val, sizeof(int)) == -1) {
- report_error("SO_REUSEADDR","can't set socket option SO_REUSEADDR");
- }
-
// Don't wait when shutting down
linger lngr;
lngr.l_onoff = 1;
@@ -149,36 +119,27 @@ gr_udp_sink::gr_udp_sink (size_t itemsize,
}
}
- // bind socket to an address and port number to listen on
- if(bind (d_socket, ip_src->ai_addr, ip_src->ai_addrlen) == -1) {
- report_error("socket bind","can't bind socket");
- }
-
- // Not sure if we should throw here or allow retries
- if(connect(d_socket, ip_dst->ai_addr, ip_dst->ai_addrlen) == -1) {
- report_error("socket connect","can't connect to socket");
- }
-
- freeaddrinfo(ip_src);
- freeaddrinfo(ip_dst);
+ // Get the destination address
+ connect(host, port);
}
// public constructor that returns a shared_ptr
gr_udp_sink_sptr
gr_make_udp_sink (size_t itemsize,
- const char *src, unsigned short port_src,
- const char *dst, unsigned short port_dst,
- int payload_size)
+ const char *host, unsigned short port,
+ int payload_size, bool eof)
{
return gr_udp_sink_sptr (new gr_udp_sink (itemsize,
- src, port_src,
- dst, port_dst,
- payload_size));
+ host, port,
+ payload_size, eof));
}
gr_udp_sink::~gr_udp_sink ()
{
+ if (d_connected)
+ disconnect();
+
if (d_socket){
shutdown(d_socket, SHUT_RDWR);
#if defined(USING_WINSOCK)
@@ -208,22 +169,28 @@ gr_udp_sink::work (int noutput_items,
printf("Entered udp_sink\n");
#endif
+ gruel::scoped_lock guard(d_mutex); // protect d_socket
+
while(bytes_sent < total_size) {
bytes_to_send = std::min((ssize_t)d_payload_size, (total_size-bytes_sent));
- r = send(d_socket, (in+bytes_sent), bytes_to_send, 0);
- if(r == -1) { // error on send command
- 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
+ if(d_connected) {
+ r = send(d_socket, (in+bytes_sent), bytes_to_send, 0);
+ if(r == -1) { // error on send command
+ 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
+ }
}
}
+ else
+ r = bytes_to_send; // discarded for lack of connection
bytes_sent += r;
#if SNK_VERBOSE
- printf("\tbyte sent: %d bytes\n", bytes);
+ printf("\tbyte sent: %d bytes\n", r);
#endif
}
@@ -233,3 +200,71 @@ gr_udp_sink::work (int noutput_items,
return noutput_items;
}
+
+void gr_udp_sink::connect( const char *host, unsigned short port )
+{
+ if(d_connected)
+ disconnect();
+
+ if(host != NULL ) {
+ // Get the destination address
+ struct addrinfo *ip_dst;
+ struct addrinfo hints;
+ memset( (void*)&hints, 0, sizeof(hints) );
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_protocol = IPPROTO_UDP;
+ char port_str[12];
+ sprintf( port_str, "%d", port );
+ int ret = getaddrinfo( host, port_str, &hints, &ip_dst );
+ if( ret != 0 )
+ report_error("gr_udp_source/getaddrinfo",
+ "can't initialize destination socket" );
+
+ // don't need d_mutex lock when !d_connected
+ if(::connect(d_socket, ip_dst->ai_addr, ip_dst->ai_addrlen) == -1) {
+ report_error("socket connect","can't connect to socket");
+ }
+ d_connected = true;
+
+ freeaddrinfo(ip_dst);
+ }
+
+ return;
+}
+
+void gr_udp_sink::disconnect()
+{
+ if(!d_connected)
+ return;
+
+ #if SNK_VERBOSE
+ printf("gr_udp_sink disconnecting\n");
+ #endif
+
+ gruel::scoped_lock guard(d_mutex); // protect d_socket from work()
+
+ // Send a few zero-length packets to signal receiver we are done
+ if(d_eof) {
+ int i;
+ for( i = 0; i < 3; i++ )
+ (void) send( d_socket, NULL, 0, 0 ); // ignore errors
+ }
+
+ // Since I can't find any way to disconnect a datagram socket in Cygwin,
+ // we just leave it connected but disable sending.
+#if 0
+ // zeroed address structure should reset connection
+ struct sockaddr addr;
+ memset( (void*)&addr, 0, sizeof(addr) );
+ // addr.sa_family = AF_UNSPEC; // doesn't work on Cygwin
+ // addr.sa_family = AF_INET; // doesn't work on Cygwin
+
+ if(::connect(d_socket, &addr, sizeof(addr)) == -1)
+ report_error("socket connect","can't connect to socket");
+#endif
+
+ d_connected = false;
+
+ return;
+}
diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h
index 6b6ee40fe..421d514a4 100644..100755
--- a/gnuradio-core/src/lib/io/gr_udp_sink.h
+++ b/gnuradio-core/src/lib/io/gr_udp_sink.h
@@ -24,14 +24,6 @@
#define INCLUDED_GR_UDP_SINK_H
#include <gr_sync_block.h>
-#if defined(HAVE_NETDB_H)
-#include <netdb.h>
-#include <sys/socket.h> // usually #included by <netdb.h>?
-#elif defined(HAVE_WINDOWS_H)
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#endif
-
#include <gruel/thread.h>
class gr_udp_sink;
@@ -39,55 +31,52 @@ typedef boost::shared_ptr<gr_udp_sink> gr_udp_sink_sptr;
gr_udp_sink_sptr
gr_make_udp_sink (size_t itemsize,
- const char *src, unsigned short port_src,
- const char *dst, unsigned short port_dst,
- int payload_size=1472);
+ const char *host, unsigned short port,
+ int payload_size=1472, bool eof=true);
/*!
* \brief Write stream to an UDP socket.
* \ingroup sink_blk
*
* \param itemsize The size (in bytes) of the item datatype
- * \param src The source address as either the host name or the 'numbers-and-dots'
- * IP address
- * \param port_src Destination port to bind to (0 allows socket to choose an appropriate port)
- * \param dst The destination address as either the host name or the 'numbers-and-dots'
- * IP address
- * \param port_dst Destination port to connect to
- * \param payload_size UDP payload size by default set to
- * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header))
+ * \param host The name or IP address of the receiving host; use
+ * NULL or None for no connection
+ * \param port Destination port to connect to on receiving host
+ * \param payload_size UDP payload size by default set to 1472 =
+ * (1500 MTU - (8 byte UDP header) - (20 byte IP header))
+ * \param eof Send zero-length packet on disconnect
*/
class gr_udp_sink : public gr_sync_block
{
friend gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize,
- const char *src, unsigned short port_src,
- const char *dst, unsigned short port_dst,
- int payload_size);
+ const char *host,
+ unsigned short port,
+ int payload_size, bool eof);
private:
size_t d_itemsize;
- int d_payload_size; // maximum transmission unit (packet length)
- int d_socket; // handle to socket
+ int d_payload_size; // maximum transmission unit (packet length)
+ bool d_eof; // send zero-length packet on disconnect
+ int d_socket; // handle to socket
+ bool d_connected; // are we connected?
+ gruel::mutex d_mutex; // protects d_socket and d_connected
protected:
/*!
* \brief UDP Sink Constructor
*
* \param itemsize The size (in bytes) of the item datatype
- * \param src The source address as either the host name or the 'numbers-and-dots'
- * IP address
- * \param port_src Destination port to bind to (0 allows socket to choose an appropriate port)
- * \param dst The destination address as either the host name or the 'numbers-and-dots'
- * IP address
- * \param port_dst Destination port to connect to
+ * \param host The name or IP address of the receiving host; use
+ * NULL or None for no connection
+ * \param port Destination port to connect to on receiving host
* \param payload_size UDP payload size by default set to
* 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header))
+ * \param eof Send zero-length packet on disconnect
*/
gr_udp_sink (size_t itemsize,
- const char *src, unsigned short port_src,
- const char *dst, unsigned short port_dst,
- int payload_size);
+ const char *host, unsigned short port,
+ int payload_size, bool eof);
public:
~gr_udp_sink ();
@@ -95,6 +84,23 @@ class gr_udp_sink : public gr_sync_block
/*! \brief return the PAYLOAD_SIZE of the socket */
int payload_size() { return d_payload_size; }
+ /*! \brief Change the connection to a new destination
+ *
+ * \param host The name or IP address of the receiving host; use
+ * NULL or None to break the connection without closing
+ * \param port Destination port to connect to on receiving host
+ *
+ * Calls disconnect() to terminate any current connection first.
+ */
+ void connect( const char *host, unsigned short port );
+
+ /*! \brief Send zero-length packet (if eof is requested) then stop sending
+ *
+ * Zero-byte packets can be interpreted as EOF by gr_udp_source. Note that
+ * disconnect occurs automatically when the sink is destroyed, but not when
+ * its top_block stops.*/
+ void disconnect();
+
// should we export anything else?
int work (int noutput_items,
diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.i b/gnuradio-core/src/lib/io/gr_udp_sink.i
index 0f37b477b..fc8059f36 100644..100755
--- a/gnuradio-core/src/lib/io/gr_udp_sink.i
+++ b/gnuradio-core/src/lib/io/gr_udp_sink.i
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright 2007,2010 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -25,22 +25,21 @@ GR_SWIG_BLOCK_MAGIC(gr,udp_sink)
gr_udp_sink_sptr
gr_make_udp_sink (size_t itemsize,
- const char *src, unsigned short port_src,
- const char *dst, unsigned short port_dst,
- int payload_size=1472);
+ const char *host, unsigned short port,
+ int payload_size=1472, bool eof=true);
class gr_udp_sink : public gr_sync_block
{
protected:
gr_udp_sink (size_t itemsize,
- const char *src, unsigned short port_src,
- const char *dst, unsigned short port_dst,
- int payload_size);
-
- bool open();
- void close();
- int payload_size() { return d_payload_size; }
+ const char *host, unsigned short port,
+ int payload_size, bool eof);
public:
~gr_udp_sink ();
+
+ int payload_size() { return d_payload_size; }
+ void connect( const char *host, unsigned short port );
+ void disconnect();
+
};
diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc
index ce870d481..880388e5e 100755
--- a/gnuradio-core/src/lib/io/gr_udp_source.cc
+++ b/gnuradio-core/src/lib/io/gr_udp_source.cc
@@ -29,9 +29,19 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
+
#if defined(HAVE_NETDB_H)
#include <netdb.h>
typedef void* optval_t;
+
+// ntohs() on FreeBSD may require both netinet/in.h and arpa/inet.h, in order
+#if defined(HAVE_NETINET_IN_H)
+#include <netinet/in.h>
+#endif
+#if defined(HAVE_ARPA_INET_H)
+#include <arpa/inet.h>
+#endif
+
#elif defined(HAVE_WINDOWS_H)
// if not posix, assume winsock
#define USING_WINSOCK
@@ -67,7 +77,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)
@@ -81,16 +91,16 @@ static void report_error( char *msg1, char *msg2 )
return;
}
-gr_udp_source::gr_udp_source(size_t itemsize, const char *src,
- unsigned short port_src, int payload_size,
- bool wait)
+gr_udp_source::gr_udp_source(size_t itemsize, const char *host,
+ unsigned short port, int payload_size,
+ bool eof, bool wait)
: gr_sync_block ("udp_source",
gr_make_io_signature(0, 0, 0),
gr_make_io_signature(1, 1, itemsize)),
- d_itemsize(itemsize), d_payload_size(payload_size), d_wait(wait), d_residual(0), d_temp_offset(0)
+ d_itemsize(itemsize), d_payload_size(payload_size),
+ d_eof(eof), d_wait(wait), d_residual(0), d_temp_offset(0)
{
int ret = 0;
- struct addrinfo *ip_src; // store the source IP address to use
#if defined(USING_WINSOCK) // for Windows (with MinGW)
// initialize winsock DLL
@@ -103,14 +113,16 @@ gr_udp_source::gr_udp_source(size_t itemsize, const char *src,
// Set up the address stucture for the source address and port numbers
// Get the source IP address from the host name
+ struct addrinfo *ip_src; // store the source IP address to use
struct addrinfo hints;
memset( (void*)&hints, 0, sizeof(hints) );
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP;
- char port_str[7];
- sprintf( port_str, "%d", port_src );
- ret = getaddrinfo( src, port_str, &hints, &ip_src );
+ hints.ai_flags = AI_PASSIVE;
+ char port_str[12];
+ sprintf( port_str, "%d", port );
+ ret = getaddrinfo( host, port_str, &hints, &ip_src );
if( ret != 0 )
report_error("gr_udp_source/getaddrinfo",
"can't initialize source socket" );
@@ -166,10 +178,10 @@ gr_udp_source::gr_udp_source(size_t itemsize, const char *src,
gr_udp_source_sptr
gr_make_udp_source (size_t itemsize, const char *ipaddr,
- unsigned short port, int payload_size, bool wait)
+ unsigned short port, int payload_size, bool eof, bool wait)
{
return gr_udp_source_sptr (new gr_udp_source (itemsize, ipaddr,
- port, payload_size, wait));
+ port, payload_size, eof, wait));
}
gr_udp_source::~gr_udp_source ()
@@ -279,6 +291,22 @@ gr_udp_source::work (int noutput_items,
return -1;
}
}
+ else if(r==0) {
+ if(d_eof) {
+ // zero-length packet interpreted as EOF
+
+ #if SNK_VERBOSE
+ printf("\tzero-length packet received; returning EOF\n");
+ #endif
+
+ return -1;
+ }
+ else{
+ // do we need to allow boost thread interrupt?
+ boost::this_thread::interruption_point();
+ continue;
+ }
+ }
else {
// Calculate the number of bytes we can take from the buffer in this call
nbytes = std::min(r, total_bytes-bytes_received);
@@ -316,3 +344,15 @@ gr_udp_source::work (int noutput_items,
return bytes_received/d_itemsize;
}
+// Return port number of d_socket
+int gr_udp_source::get_port(void)
+{
+ sockaddr_in name;
+ socklen_t len = sizeof(name);
+ int ret = getsockname( d_socket, (sockaddr*)&name, &len );
+ if( ret ) {
+ report_error("gr_udp_source/getsockname",NULL);
+ return -1;
+ }
+ return ntohs(name.sin_port);
+}
diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h
index b06536d6a..e23231aa7 100755
--- a/gnuradio-core/src/lib/io/gr_udp_source.h
+++ b/gnuradio-core/src/lib/io/gr_udp_source.h
@@ -24,49 +24,48 @@
#define INCLUDED_GR_UDP_SOURCE_H
#include <gr_sync_block.h>
-#if defined(HAVE_NETDB_H)
-#include <netdb.h>
-#include <sys/socket.h> // usually #included by <netdb.h>?
-#elif defined(HAVE_WINDOWS_H)
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#endif
-
#include <gruel/thread.h>
class gr_udp_source;
typedef boost::shared_ptr<gr_udp_source> gr_udp_source_sptr;
-gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src,
- unsigned short port_src,
- int payload_size=1472, bool wait=true);
+gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *host,
+ unsigned short port,
+ int payload_size=1472,
+ bool eof=true, bool wait=true);
/*!
* \brief Read stream from an UDP socket.
* \ingroup source_blk
*
* \param itemsize The size (in bytes) of the item datatype
- * \param src The source address as either the host name or the 'numbers-and-dots'
- * IP address
- * \param port_src The port number on which the socket listens for data
- * \param payload_size UDP payload size by default set to
- * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header))
- * \param wait Wait for data if not immediately available (default: true)
+ * \param host The name or IP address of the receiving host; can be
+ * NULL, None, or "0.0.0.0" to allow reading from any
+ * interface on the host
+ * \param port The port number on which to receive data; use 0 to
+ * have the system assign an unused port number
+ * \param payload_size UDP payload size by default set to 1472 =
+ * (1500 MTU - (8 byte UDP header) - (20 byte IP header))
+ * \param eof Interpret zero-length packet as EOF (default: true)
+ * \param wait Wait for data if not immediately available
+ * (default: true)
*
*/
class gr_udp_source : public gr_sync_block
{
- friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src,
- unsigned short port_src,
- int payload_size, bool wait);
+ friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize,
+ const char *host,
+ unsigned short port,
+ int payload_size,
+ bool eof, bool wait);
private:
size_t d_itemsize;
-
- int d_payload_size; // maximum transmission unit (packet length)
- bool d_wait; // wait if data if not immediately available
- int d_socket; // handle to socket
+ int d_payload_size; // maximum transmission unit (packet length)
+ bool d_eof; // zero-length packet is EOF
+ bool d_wait; // wait if data if not immediately available
+ int d_socket; // handle to socket
char *d_temp_buff; // hold buffer between calls
ssize_t d_residual; // hold information about number of bytes stored in the temp buffer
size_t d_temp_offset; // point to temp buffer location offset
@@ -76,15 +75,19 @@ class gr_udp_source : public gr_sync_block
* \brief UDP Source Constructor
*
* \param itemsize The size (in bytes) of the item datatype
- * \param src The source address as either the host name or the 'numbers-and-dots'
- * IP address
- * \param port_src The port number on which the socket listens for data
- * \param payload_size UDP payload size by default set to
- * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header))
- * \param wait Wait for data if not immediately available (default: true)
+ * \param host The name or IP address of the receiving host; can be
+ * NULL, None, or "0.0.0.0" to allow reading from any
+ * interface on the host
+ * \param port The port number on which to receive data; use 0 to
+ * have the system assign an unused port number
+ * \param payload_size UDP payload size by default set to 1472 =
+ * (1500 MTU - (8 byte UDP header) - (20 byte IP header))
+ * \param eof Interpret zero-length packet as EOF (default: true)
+ * \param wait Wait for data if not immediately available
+ * (default: true)
*/
- gr_udp_source(size_t itemsize, const char *src, unsigned short port_src,
- int payload_size, bool wait);
+ gr_udp_source(size_t itemsize, const char *host, unsigned short port,
+ int payload_size, bool eof, bool wait);
public:
~gr_udp_source();
@@ -92,6 +95,9 @@ class gr_udp_source : public gr_sync_block
/*! \brief return the PAYLOAD_SIZE of the socket */
int payload_size() { return d_payload_size; }
+ /*! \breif return the port number of the socket */
+ int get_port();
+
// should we export anything else?
int work(int noutput_items,
diff --git a/gnuradio-core/src/lib/io/gr_udp_source.i b/gnuradio-core/src/lib/io/gr_udp_source.i
index efaa57c27..e1b23074d 100755
--- a/gnuradio-core/src/lib/io/gr_udp_source.i
+++ b/gnuradio-core/src/lib/io/gr_udp_source.i
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright 2007,2010 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -23,19 +23,19 @@
GR_SWIG_BLOCK_MAGIC(gr,udp_source)
gr_udp_source_sptr
-gr_make_udp_source (size_t itemsize, const char *src,
- unsigned short port_src, int payload_size=1472,
- bool wait=true);
+gr_make_udp_source (size_t itemsize, const char *host,
+ unsigned short port, int payload_size=1472,
+ bool eof=true, bool wait=true);
class gr_udp_source : public gr_sync_block
{
protected:
- gr_udp_source (size_t itemsize, const char *src,
- unsigned short port_src, int payload_size, bool wait);
+ gr_udp_source (size_t itemsize, const char *host,
+ unsigned short port, int payload_size, bool eof, bool wait);
public:
~gr_udp_source ();
int payload_size() { return d_payload_size; }
-
+ int get_port();
};