3 * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #ifndef INCLUDED_GR_UDP_SINK_H
24 #define INCLUDED_GR_UDP_SINK_H
26 #include <gr_sync_block.h>
27 #include <gruel/thread.h>
30 typedef boost::shared_ptr<gr_udp_sink> gr_udp_sink_sptr;
33 gr_make_udp_sink (size_t itemsize,
34 const char *host, unsigned short port,
35 int payload_size=1472, bool eof=true);
38 * \brief Write stream to an UDP socket.
41 * \param itemsize The size (in bytes) of the item datatype
42 * \param host The name or IP address of the receiving host; use
43 * NULL or None for no connection
44 * \param port Destination port to connect to on receiving host
45 * \param payload_size UDP payload size by default set to 1472 =
46 * (1500 MTU - (8 byte UDP header) - (20 byte IP header))
47 * \param eof Send zero-length packet on disconnect
50 class gr_udp_sink : public gr_sync_block
52 friend gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize,
55 int payload_size, bool eof);
59 int d_payload_size; // maximum transmission unit (packet length)
60 bool d_eof; // send zero-length packet on disconnect
61 int d_socket; // handle to socket
62 bool d_connected; // are we connected?
63 gruel::mutex d_mutex; // protects d_socket and d_connected
67 * \brief UDP Sink Constructor
69 * \param itemsize The size (in bytes) of the item datatype
70 * \param host The name or IP address of the receiving host; use
71 * NULL or None for no connection
72 * \param port Destination port to connect to on receiving host
73 * \param payload_size UDP payload size by default set to
74 * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP header))
75 * \param eof Send zero-length packet on disconnect
77 gr_udp_sink (size_t itemsize,
78 const char *host, unsigned short port,
79 int payload_size, bool eof);
84 /*! \brief return the PAYLOAD_SIZE of the socket */
85 int payload_size() { return d_payload_size; }
87 /*! \brief Change the connection to a new destination
89 * \param host The name or IP address of the receiving host; use
90 * NULL or None to break the connection without closing
91 * \param port Destination port to connect to on receiving host
93 * Calls disconnect() to terminate any current connection first.
95 void connect( const char *host, unsigned short port );
97 /*! \brief Send zero-length packet (if eof is requested) then stop sending
99 * Zero-byte packets can be interpreted as EOF by gr_udp_source. Note that
100 * disconnect occurs automatically when the sink is destroyed, but not when
101 * its top_block stops.*/
104 // should we export anything else?
106 int work (int noutput_items,
107 gr_vector_const_void_star &input_items,
108 gr_vector_void_star &output_items);
111 #endif /* INCLUDED_GR_UDP_SINK_H */