GNU Radio 3.6.2 C++ API
gr_udp_source.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22 
23 #ifndef INCLUDED_GR_UDP_SOURCE_H
24 #define INCLUDED_GR_UDP_SOURCE_H
25 
26 #include <gr_core_api.h>
27 #include <gr_sync_block.h>
28 #include <gruel/thread.h>
29 
30 class gr_udp_source;
32 
33 GR_CORE_API gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *host,
34  unsigned short port,
35  int payload_size=1472,
36  bool eof=true, bool wait=true);
37 
38 /*!
39  * \brief Read stream from an UDP socket.
40  * \ingroup source_blk
41  *
42  * \param itemsize The size (in bytes) of the item datatype
43  * \param host The name or IP address of the receiving host; can be
44  * NULL, None, or "0.0.0.0" to allow reading from any
45  * interface on the host
46  * \param port The port number on which to receive data; use 0 to
47  * have the system assign an unused port number
48  * \param payload_size UDP payload size by default set to 1472 =
49  * (1500 MTU - (8 byte UDP header) - (20 byte IP header))
50  * \param eof Interpret zero-length packet as EOF (default: true)
51  * \param wait Wait for data if not immediately available
52  * (default: true)
53  *
54 */
55 
57 {
58  friend GR_CORE_API gr_udp_source_sptr gr_make_udp_source(size_t itemsize,
59  const char *host,
60  unsigned short port,
61  int payload_size,
62  bool eof, bool wait);
63 
64  private:
65  size_t d_itemsize;
66  int d_payload_size; // maximum transmission unit (packet length)
67  bool d_eof; // zero-length packet is EOF
68  bool d_wait; // wait if data if not immediately available
69  int d_socket; // handle to socket
70  char *d_temp_buff; // hold buffer between calls
71  ssize_t d_residual; // hold information about number of bytes stored in the temp buffer
72  size_t d_temp_offset; // point to temp buffer location offset
73 
74  protected:
75  /*!
76  * \brief UDP Source Constructor
77  *
78  * \param itemsize The size (in bytes) of the item datatype
79  * \param host The name or IP address of the receiving host; can be
80  * NULL, None, or "0.0.0.0" to allow reading from any
81  * interface on the host
82  * \param port The port number on which to receive data; use 0 to
83  * have the system assign an unused port number
84  * \param payload_size UDP payload size by default set to 1472 =
85  * (1500 MTU - (8 byte UDP header) - (20 byte IP header))
86  * \param eof Interpret zero-length packet as EOF (default: true)
87  * \param wait Wait for data if not immediately available
88  * (default: true)
89  */
90  gr_udp_source(size_t itemsize, const char *host, unsigned short port,
91  int payload_size, bool eof, bool wait);
92 
93  public:
94  ~gr_udp_source();
95 
96  /*! \brief return the PAYLOAD_SIZE of the socket */
97  int payload_size() { return d_payload_size; }
98 
99  /*! \brief return the port number of the socket */
100  int get_port();
101 
102  // should we export anything else?
103 
104  int work(int noutput_items,
105  gr_vector_const_void_star &input_items,
106  gr_vector_void_star &output_items);
107 };
108 
109 
110 #endif /* INCLUDED_GR_UDP_SOURCE_H */