diff options
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/udp_source.h | 4 | ||||
-rw-r--r-- | gr-blocks/lib/udp_source_impl.cc | 25 | ||||
-rw-r--r-- | gr-blocks/lib/udp_source_impl.h | 2 |
3 files changed, 18 insertions, 13 deletions
diff --git a/gr-blocks/include/gnuradio/blocks/udp_source.h b/gr-blocks/include/gnuradio/blocks/udp_source.h index 67c31a7c60..d1b4062b79 100644 --- a/gr-blocks/include/gnuradio/blocks/udp_source.h +++ b/gr-blocks/include/gnuradio/blocks/udp_source.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007-2010,2013 Free Software Foundation, Inc. + * Copyright 2007-2010,2013,2015 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -43,7 +43,7 @@ namespace gr { * \brief UDP Source Constructor * * \param itemsize The size (in bytes) of the item datatype - * \param host The name or IP address of the receiving host; can be + * \param host The name or IP address of the transmitting 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 diff --git a/gr-blocks/lib/udp_source_impl.cc b/gr-blocks/lib/udp_source_impl.cc index ca4018464d..b1977a8fce 100644 --- a/gr-blocks/lib/udp_source_impl.cc +++ b/gr-blocks/lib/udp_source_impl.cc @@ -35,6 +35,8 @@ namespace gr { namespace blocks { + const int udp_source_impl::BUF_SIZE_PAYLOADS = 50; + udp_source::sptr udp_source::make(size_t itemsize, const std::string &ipaddr, int port, @@ -56,7 +58,7 @@ namespace gr { { // Give us some more room to play. d_rxbuf = new char[4*d_payload_size]; - d_residbuf = new char[50*d_payload_size]; + d_residbuf = new char[BUF_SIZE_PAYLOADS*d_payload_size]; connect(host, port); } @@ -150,7 +152,7 @@ namespace gr { if(d_eof && (bytes_transferred == 1) && (d_rxbuf[0] == 0x00)) { // If we are using EOF notification, test for it and don't // add anything to the output. - d_residual = -1; + d_residual = WORK_DONE; d_cond_wait.notify_one(); return; } @@ -158,7 +160,7 @@ namespace gr { // Make sure we never go beyond the boundary of the // residual buffer. This will just drop the last bit of // data in the buffer if we've run out of room. - if((int)(d_residual + bytes_transferred) >= (50*d_payload_size)) { + if((int)(d_residual + bytes_transferred) >= (BUF_SIZE_PAYLOADS*d_payload_size)) { GR_LOG_WARN(d_logger, "Too much data; dropping packet."); } else { @@ -192,24 +194,25 @@ namespace gr { //use timed_wait to avoid permanent blocking in the work function d_cond_wait.timed_wait(lock, boost::posix_time::milliseconds(10)); - if(d_residual < 0) - return -1; + if (d_residual < 0) { + return d_residual; + } - int to_be_sent = (int)(d_residual - d_sent); - int to_send = std::min(noutput_items, to_be_sent); + int bytes_left_in_buffer = (int)(d_residual - d_sent); + int bytes_to_send = std::min<int>(d_itemsize * noutput_items, bytes_left_in_buffer); // Copy the received data in the residual buffer to the output stream - memcpy(out, d_residbuf+d_sent, to_send); - int nitems = to_send/d_itemsize; + memcpy(out, d_residbuf+d_sent, bytes_to_send); + int nitems = bytes_to_send/d_itemsize; // Keep track of where we are if we don't have enough output // space to send all the data in the residbuf. - if(to_send == to_be_sent) { + if (bytes_to_send == bytes_left_in_buffer) { d_residual = 0; d_sent = 0; } else { - d_sent += to_send; + d_sent += bytes_to_send; } return nitems; diff --git a/gr-blocks/lib/udp_source_impl.h b/gr-blocks/lib/udp_source_impl.h index 949364cf29..42cb64dabe 100644 --- a/gr-blocks/lib/udp_source_impl.h +++ b/gr-blocks/lib/udp_source_impl.h @@ -44,6 +44,8 @@ namespace gr { ssize_t d_sent; // track how much of d_residbuf we've outputted size_t d_offset; // point to residbuf location offset + static const int BUF_SIZE_PAYLOADS; //!< The d_residbuf size in multiples of d_payload_size + std::string d_host; unsigned short d_port; |