[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 06/17: blocks: added 'MTU' (buffer size) &
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 06/17: blocks: added 'MTU' (buffer size) & 'no_delay' params to 'tcp_connection' (no longer uses fixed buffer) |
Date: |
Mon, 31 Mar 2014 20:15:53 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit c20fdf517b6dd9e0f7e94edce85d243a4e429aca
Author: Balint Seeber <address@hidden>
Date: Wed Mar 26 23:54:29 2014 -0700
blocks: added 'MTU' (buffer size) & 'no_delay' params to 'tcp_connection'
(no longer uses fixed buffer)
---
gr-blocks/lib/tcp_connection.cc | 50 ++++++++++++++++++++++++++---------------
gr-blocks/lib/tcp_connection.h | 8 +++----
2 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/gr-blocks/lib/tcp_connection.cc b/gr-blocks/lib/tcp_connection.cc
index ce719d1..970732e 100644
--- a/gr-blocks/lib/tcp_connection.cc
+++ b/gr-blocks/lib/tcp_connection.cc
@@ -31,55 +31,69 @@
namespace gr {
namespace blocks {
- tcp_connection::sptr tcp_connection::make(boost::asio::io_service&
io_service)
+ tcp_connection::sptr tcp_connection::make(boost::asio::io_service&
io_service, int MTU/*= 10000*/, bool no_delay/*=false*/)
{
- return sptr(new tcp_connection(io_service));
+ return sptr(new tcp_connection(io_service, MTU, no_delay));
}
- tcp_connection::tcp_connection(boost::asio::io_service& io_service)
+ tcp_connection::tcp_connection(boost::asio::io_service& io_service, int
MTU/*= 10000*/, bool no_delay/*=false*/)
: d_socket(io_service)
+ , d_block(NULL)
+ , d_no_delay(no_delay)
{
+ d_buf.resize(MTU);
+ try {
+ d_socket.set_option(boost::asio::ip::tcp::no_delay(no_delay));
+ }
+ catch (...) {
+ // Silently ignore failure (socket might be current in accept stage)
and try again in 'start'
+ }
}
void
tcp_connection::send(pmt::pmt_t vector)
{
size_t len = pmt::length(vector);
- size_t offset(0);
- boost::array<char, 10000> txbuf;
- memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), len);
- boost::asio::async_write(d_socket, boost::asio::buffer(txbuf, len),
+ size_t offset = 0;
+ std::vector<char> txbuf(std::min(len, d_buf.size()));
+ while (offset < len) {
+ size_t send_len = std::min((len - offset), txbuf.size());
+ memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset),
send_len);
+ offset += send_len;
+ boost::asio::async_write(d_socket, boost::asio::buffer(txbuf,
send_len),
boost::bind(&tcp_connection::handle_write, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
+ }
}
void
tcp_connection::start(gr::basic_block *block)
{
d_block = block;
+ d_socket.set_option(boost::asio::ip::tcp::no_delay(d_no_delay));
d_socket.async_read_some(boost::asio::buffer(d_buf),
- boost::bind(&tcp_connection::handle_read, this,
- boost::asio::placeholders::error,
-
boost::asio::placeholders::bytes_transferred));
+ boost::bind(&tcp_connection::handle_read, this,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred));
}
void
tcp_connection::handle_read(const boost::system::error_code& error, size_t
bytes_transferred)
{
if (!error) {
- pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const
uint8_t*)&d_buf[0]);
- pmt::pmt_t pdu = pmt::cons( pmt::PMT_NIL, vector);
+ if (d_block) {
+ pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const
uint8_t*)&d_buf[0]);
+ pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector);
- d_block->message_port_pub(PDU_PORT_ID, pdu);
+ d_block->message_port_pub(PDU_PORT_ID, pdu);
+ }
d_socket.async_read_some(boost::asio::buffer(d_buf),
- boost::bind(&tcp_connection::handle_read, this,
- boost::asio::placeholders::error,
-
boost::asio::placeholders::bytes_transferred));
-
+ boost::bind(&tcp_connection::handle_read, this,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred));
}
}
-
} /* namespace blocks */
}/* namespace gr */
diff --git a/gr-blocks/lib/tcp_connection.h b/gr-blocks/lib/tcp_connection.h
index f4d32fa..9193928 100644
--- a/gr-blocks/lib/tcp_connection.h
+++ b/gr-blocks/lib/tcp_connection.h
@@ -37,16 +37,16 @@ namespace gr {
{
private:
boost::asio::ip::tcp::socket d_socket;
- boost::array<char, 10000> d_buf;
- std::string d_message;
+ std::vector<char> d_buf;
basic_block *d_block;
+ bool d_no_delay;
- tcp_connection(boost::asio::io_service& io_service);
+ tcp_connection(boost::asio::io_service& io_service, int MTU=10000, bool
no_delay=false);
public:
typedef boost::shared_ptr<tcp_connection> sptr;
- static sptr make(boost::asio::io_service& io_service);
+ static sptr make(boost::asio::io_service& io_service, int MTU=10000,
bool no_delay=false);
boost::asio::ip::tcp::socket& socket() { return d_socket; };
- [Commit-gnuradio] [gnuradio] branch master updated (a8f73d8 -> 7390c25), git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 01/17: runtime: restoring sanity to pmt.is_blob(), git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 09/17: Add matching HDLC framer. Fix deframer max/min., git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 04/17: blocks: hide 'ignore tag' param for 'throttle' block in GRC if it's the default value (i.e. old look before param was added), git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 11/17: Merge remote-tracking branch 'osh/pmt_fix', git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 02/17: Add HDLC deframer to gr-digital. Input unpacked bits, output PDU binary blobs., git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 07/17: blocks: added 'MTU' and 'tcp_no_delay' params for 'socket_pdu' (and GRC option), applied MTU (buffer size) to TCP/UDP send, separate TCP/UDP server endpoint resolvers for empty/0.0.0.0 Host param (listen on all interfaces) Whitespace clean-up., git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 06/17: blocks: added 'MTU' (buffer size) & 'no_delay' params to 'tcp_connection' (no longer uses fixed buffer),
git <=
- [Commit-gnuradio] [gnuradio] 16/17: Merge remote-tracking branch 'balint/3.7-1/socket_pdu_improvements', git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 05/17: digital: added 'byte' IO format, git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 08/17: cmake: updated max ver for FindQwt to 6.2.0 (Qwt compiled direct from their source tree worked with trondeau's qt_number_sink test FG), git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 10/17: Add QA code to HDLC framer/deframer., git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 17/17: Merge remote-tracking branch 'balint/3.7-1/findqwt_max_ver_6.2.0', git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 12/17: Merge remote-tracking branch 'bistromath/hdlc', git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 15/17: Merge remote-tracking branch 'balint/3.7-1/throttle_grc_hide_ignoretag', git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 13/17: Merge remote-tracking branch 'balint/3.7-1/tcp_connection_mtu_no_delay', git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 14/17: Merge remote-tracking branch 'balint/3.7-1/header_payload_demux_byte_type', git, 2014/03/31
- [Commit-gnuradio] [gnuradio] 03/17: fix numpy to pmt uvector conversion, git, 2014/03/31