summaryrefslogtreecommitdiff
path: root/gr-blocks/lib/socket_pdu_impl.cc
diff options
context:
space:
mode:
authorMarcus Müller <mueller@kit.edu>2018-02-20 15:47:12 +0100
committerMarcus Müller <marcus@hostalia.de>2018-02-23 19:06:50 +0100
commit2fc414578985b59c5bfbb15103f3c3677a1c6fdc (patch)
tree082f8be4333be7fa3264fdf09c30d61ce3ec033d /gr-blocks/lib/socket_pdu_impl.cc
parent4cce1a032a929d72948d54c2b429dc8ebd530a36 (diff)
blocks: don't pmt::mp("string") for every single PDU
Replaced the usage of `#define PDU_PORT_ID pmt::mp("pdus")` – that was the actual way to *enforce* rehashing on every single use. Now, static const member of namespace `gr::blocks::pdu` as `s_pdu_port_id`. Should speed up the PDU blocks a bit. Removes run-time malloc'ing. Good thing.
Diffstat (limited to 'gr-blocks/lib/socket_pdu_impl.cc')
-rw-r--r--gr-blocks/lib/socket_pdu_impl.cc18
1 files changed, 9 insertions, 9 deletions
diff --git a/gr-blocks/lib/socket_pdu_impl.cc b/gr-blocks/lib/socket_pdu_impl.cc
index efb778f404..2e154d2c1f 100644
--- a/gr-blocks/lib/socket_pdu_impl.cc
+++ b/gr-blocks/lib/socket_pdu_impl.cc
@@ -46,8 +46,8 @@ namespace gr {
{
d_rxbuf.resize(MTU);
- message_port_register_in(PDU_PORT_ID);
- message_port_register_out(PDU_PORT_ID);
+ message_port_register_in(pdu::s_pdu_port_id);
+ message_port_register_out(pdu::s_pdu_port_id);
if ((type == "TCP_SERVER") && ((addr.empty()) || (addr == "0.0.0.0"))) { // Bind on all interfaces
int port_num = atoi(port.c_str());
@@ -86,7 +86,7 @@ namespace gr {
start_tcp_accept();
- set_msg_handler(PDU_PORT_ID, boost::bind(&socket_pdu_impl::tcp_server_send, this, _1));
+ set_msg_handler(pdu::s_pdu_port_id, boost::bind(&socket_pdu_impl::tcp_server_send, this, _1));
}
else if (type =="TCP_CLIENT") {
boost::system::error_code error = boost::asio::error::host_not_found;
@@ -96,7 +96,7 @@ namespace gr {
throw boost::system::system_error(error);
d_tcp_socket->set_option(boost::asio::ip::tcp::no_delay(d_tcp_no_delay));
- set_msg_handler(PDU_PORT_ID, boost::bind(&socket_pdu_impl::tcp_client_send, this, _1));
+ set_msg_handler(pdu::s_pdu_port_id, boost::bind(&socket_pdu_impl::tcp_client_send, this, _1));
d_tcp_socket->async_read_some(boost::asio::buffer(d_rxbuf),
boost::bind(&socket_pdu_impl::handle_tcp_read, this,
@@ -110,7 +110,7 @@ namespace gr {
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
- set_msg_handler(PDU_PORT_ID, boost::bind(&socket_pdu_impl::udp_send, this, _1));
+ set_msg_handler(pdu::s_pdu_port_id, boost::bind(&socket_pdu_impl::udp_send, this, _1));
}
else if (type =="UDP_CLIENT") {
d_udp_socket.reset(new boost::asio::ip::udp::socket(d_io_service, d_udp_endpoint));
@@ -119,7 +119,7 @@ namespace gr {
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
- set_msg_handler(PDU_PORT_ID, boost::bind(&socket_pdu_impl::udp_send, this, _1));
+ set_msg_handler(pdu::s_pdu_port_id, boost::bind(&socket_pdu_impl::udp_send, this, _1));
}
else
throw std::runtime_error("gr::blocks:socket_pdu: unknown socket type");
@@ -151,7 +151,7 @@ namespace gr {
if (!error) {
pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t *)&d_rxbuf[0]);
pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector);
- message_port_pub(PDU_PORT_ID, pdu);
+ message_port_pub(pdu::s_pdu_port_id, pdu);
d_tcp_socket->async_read_some(boost::asio::buffer(d_rxbuf),
boost::bind(&socket_pdu_impl::handle_tcp_read, this,
@@ -231,7 +231,7 @@ namespace gr {
memcpy(&txbuf[0], pmt::uniform_vector_elements(vector, offset), send_len);
offset += send_len;
d_udp_socket->send_to(boost::asio::buffer(txbuf, send_len), d_udp_endpoint_other);
- }
+ }
}
void
@@ -241,7 +241,7 @@ namespace gr {
pmt::pmt_t vector = pmt::init_u8vector(bytes_transferred, (const uint8_t*)&d_rxbuf[0]);
pmt::pmt_t pdu = pmt::cons(pmt::PMT_NIL, vector);
- message_port_pub(PDU_PORT_ID, pdu);
+ message_port_pub(pdu::s_pdu_port_id, pdu);
d_udp_socket->async_receive_from(boost::asio::buffer(d_rxbuf), d_udp_endpoint_other,
boost::bind(&socket_pdu_impl::handle_udp_read, this,