X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=gnuradio-core%2Fsrc%2Flib%2Fio%2Fgr_udp_source.h;fp=gnuradio-core%2Fsrc%2Flib%2Fio%2Fgr_udp_source.h;h=5d30fad3045de4c7efc4189a5d6a1cab178e930a;hb=8a9ddbb0675f9bfcc6e03b457fba6c79474a3693;hp=afc41a45a23348a822e57aa0e70de02ff8b8afc6;hpb=82d471b9b4a8b389b5da44b19c69c36420828382;p=debian%2Fgnuradio diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index afc41a45..5d30fad3 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,53 +24,48 @@ #define INCLUDED_GR_UDP_SOURCE_H #include -#include -#if defined(HAVE_SOCKET) -#include -#include -#elif defined(HAVE_WINDOWS_H) -#include -#include -#endif -#if defined(HAVE_NETINET_IN_H) -#include -#endif +#include class gr_udp_source; typedef boost::shared_ptr 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); +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 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); + 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; - bool d_updated; - omni_mutex d_mutex; - - int d_payload_size; // maximum transmission unit (packet length) - int d_socket; // handle to socket - int d_socket_rcv; // handle to socket retuned in the accept call - struct in_addr d_ip_src; // store the source IP address to use - unsigned short d_port_src; // the port number to open for connections to this service - struct sockaddr_in d_sockaddr_src; // store the source sockaddr data (formatted IP address and port number) + 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 @@ -80,35 +75,29 @@ 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 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); + gr_udp_source(size_t itemsize, const char *host, unsigned short port, + int payload_size, bool eof, bool wait); public: ~gr_udp_source(); - /*! - * \brief open a socket specified by the port and ip address info - * - * Opens a socket, binds to the address, and waits for a connection - * over UDP. If any of these fail, the fuction retuns the error and exits. - */ - bool open(); - - /*! - * \brief Close current socket. - * - * Shuts down read/write on the socket - */ - void close(); - /*! \brief return the PAYLOAD_SIZE of the socket */ int payload_size() { return d_payload_size; } + /*! \brief return the port number of the socket */ + int get_port(); + // should we export anything else? int work(int noutput_items,