gr-baz Package
baz_tcp_source.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2007,2008,2009,2010,2013 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_BAZ_TCP_SOURCE_H
24#define INCLUDED_BAZ_TCP_SOURCE_H
25
26#include <gnuradio/sync_block.h>
27#include <gnuradio/thread/thread.h>
28
29#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
30#include <cstddef>
31typedef ptrdiff_t ssize_t;
32#endif
33
34#include <stdio.h>
35
37typedef boost::shared_ptr<baz_tcp_source> baz_tcp_source_sptr;
38
39BAZ_API baz_tcp_source_sptr baz_make_tcp_source(size_t itemsize, const char *host, unsigned short port, int buffer_size=0, bool verbose=false);
40
41/*!
42 * \brief Read stream from an UDP socket.
43 * \ingroup source_blk
44 *
45 * \param itemsize The size (in bytes) of the item datatype
46 * \param host The name or IP address of the receiving host; can be
47 * NULL, None, or "0.0.0.0" to allow reading from any
48 * interface on the host
49 * \param port The port number on which to receive data; use 0 to
50 * have the system assign an unused port number
51 * \param buffer_size TCP receiver buffer size
52 * \param verbose Output BorIP packet debug messages (helpful to judge packet loss)
53 *
54*/
55
56class BAZ_API baz_tcp_source : public gr::sync_block
57{
58private:
59 friend BAZ_API baz_tcp_source_sptr baz_make_tcp_source(size_t itemsize, const char *host, unsigned short port, int buffer_size, bool verbose);
60
61 size_t d_itemsize;
62 //bool d_wait; // wait if data if not immediately available
63 int d_socket; // handle to socket
64 char *d_temp_buff; // hold buffer between calls
65 int d_temp_buff_size;
66 int d_temp_buff_used;
67 //ssize_t d_residual; // hold information about number of bytes stored in the temp buffer
68 int d_temp_offset; // point to temp buffer location offset
69 bool d_verbose;
70 bool d_eos;
71 int d_client_socket;
72 //struct sockaddr_in cli_addr;
73 char* d_client_addr;
74 unsigned int d_client_addr_len;
75 int d_packet_type;
76 int d_packet_length;
77 int d_packet_offset;
78 pmt::pmt_t d_tags;
79 bool d_new_tags;
80 int d_work_count;
81
82 void disconnect_client();
83
84protected:
85 /*!
86 * \brief UDP Source Constructor
87 *
88 * \param itemsize The size (in bytes) of the item datatype
89 * \param host The name or IP address of the receiving host; can be
90 * NULL, None, or "0.0.0.0" to allow reading from any
91 * interface on the host
92 * \param port The port number on which to receive data; use 0 to
93 * have the system assign an unused port number
94 * \param buffer_size TCP receiver buffer size
95 * \param verbose Output BorIP packet debug messages (helpful to judge packet loss)
96 */
97 baz_tcp_source(size_t itemsize, const char *host, unsigned short port, int buffer_size, bool verbose);
98
99public:
101
102 /*! \brief return the port number of the socket */
103 int get_port();
104
106
107 int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items);
108};
109
110
111#endif /* INCLUDED_BAZ_TCP_SOURCE_H */
#define BAZ_API
Definition api.h:19
BAZ_API baz_tcp_source_sptr baz_make_tcp_source(size_t itemsize, const char *host, unsigned short port, int buffer_size=0, bool verbose=false)
Read stream from an UDP socket.
Definition baz_tcp_source.h:57
baz_tcp_source(size_t itemsize, const char *host, unsigned short port, int buffer_size, bool verbose)
UDP Source Constructor.
friend BAZ_API baz_tcp_source_sptr baz_make_tcp_source(size_t itemsize, const char *host, unsigned short port, int buffer_size, bool verbose)
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
int get_port()
return the port number of the socket