diff options
author | Josh Blum <josh@joshknows.com> | 2010-04-27 09:42:36 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-04-27 09:42:36 -0700 |
commit | b920557788fc5435915584bec6ab16a97d7c6090 (patch) | |
tree | 36ad5dc6058cd7164f11f47430ba6d0ace84e6ab /host/lib | |
parent | 8497eb2ac016f72e2b9a9028e5126bc73f5b0c9a (diff) | |
download | uhd-b920557788fc5435915584bec6ab16a97d7c6090.tar.gz uhd-b920557788fc5435915584bec6ab16a97d7c6090.tar.bz2 uhd-b920557788fc5435915584bec6ab16a97d7c6090.zip |
work on controlling the socket buffer sizes from the front end api
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/transport/udp_zero_copy_asio.cpp | 34 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.cpp | 21 |
2 files changed, 34 insertions, 21 deletions
diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index 7e643abad..315ae49d2 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -19,8 +19,6 @@ #include <boost/cstdint.hpp> #include <boost/asio.hpp> #include <boost/thread.hpp> -#include <boost/format.hpp> -#include <iostream> using namespace uhd::transport; @@ -104,12 +102,13 @@ public: managed_recv_buffer::sptr get_recv_buff(void); managed_send_buffer::sptr get_send_buff(void); + //resize + size_t set_recv_buff_size(size_t num_bytes); + size_t set_send_buff_size(size_t num_bytes); + private: boost::asio::ip::udp::socket *_socket; boost::asio::io_service _io_service; - - size_t get_recv_buff_size(void); - void set_recv_buff_size(size_t); }; udp_zero_copy_impl::udp_zero_copy_impl(const std::string &addr, const std::string &port){ @@ -124,18 +123,6 @@ udp_zero_copy_impl::udp_zero_copy_impl(const std::string &addr, const std::strin _socket = new boost::asio::ip::udp::socket(_io_service); _socket->open(boost::asio::ip::udp::v4()); _socket->connect(receiver_endpoint); - - // set the rx socket buffer size: - // pick a huge size, and deal with whatever we get - set_recv_buff_size(size_t(54321e3)); //some big number! - size_t current_buff_size = get_recv_buff_size(); - std::cout << boost::format( - "Current rx socket buffer size: %d\n" - ) % current_buff_size; - if (current_buff_size < size_t(.1e6)) std::cout << boost::format( - "Adjust max rx socket buffer size (linux only):\n" - " sysctl -w net.core.rmem_max=VALUE\n" - ); } udp_zero_copy_impl::~udp_zero_copy_impl(void){ @@ -170,15 +157,20 @@ managed_send_buffer::sptr udp_zero_copy_impl::get_send_buff(void){ ); } -size_t udp_zero_copy_impl::get_recv_buff_size(void){ - boost::asio::socket_base::receive_buffer_size option; +//sysctl -w net.core.rmem_max=VALUE +size_t udp_zero_copy_impl::set_recv_buff_size(size_t num_bytes){ + boost::asio::socket_base::receive_buffer_size option(num_bytes); + _socket->set_option(option); _socket->get_option(option); return option.value(); } -void udp_zero_copy_impl::set_recv_buff_size(size_t new_size){ - boost::asio::socket_base::receive_buffer_size option(new_size); +//sysctl -w net.core.wmem_max=VALUE +size_t udp_zero_copy_impl::set_send_buff_size(size_t num_bytes){ + boost::asio::socket_base::send_buffer_size option(num_bytes); _socket->set_option(option); + _socket->get_option(option); + return option.value(); } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 4079357f9..ffcdbb43d 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -24,6 +24,7 @@ #include <boost/assign/list_of.hpp> #include <boost/format.hpp> #include <boost/foreach.hpp> +#include <boost/lexical_cast.hpp> #include <boost/bind.hpp> #include <boost/asio.hpp> //htonl and ntohl #include <iostream> @@ -117,6 +118,26 @@ device::sptr usrp2::make(const device_addr_t &device_addr){ device_addr["addr"], num2str(USRP2_UDP_DATA_PORT) ); + //resize the recv data transport buffers + if (device_addr.has_key("recv_buff_size")){ + size_t num_byes = size_t(boost::lexical_cast<double>(device_addr["recv_buff_size"])); + size_t actual_bytes = data_transport->set_recv_buff_size(num_byes); + std::cout << boost::format( + "Target recv buffer size: %d" + "Actual recv byffer size: %d" + ) % num_byes % actual_bytes << std::endl; + } + + //resize the send data transport buffers + if (device_addr.has_key("send_buff_size")){ + size_t num_byes = size_t(boost::lexical_cast<double>(device_addr["send_buff_size"])); + size_t actual_bytes = data_transport->set_send_buff_size(num_byes); + std::cout << boost::format( + "Target send buffer size: %d" + "Actual send byffer size: %d" + ) % num_byes % actual_bytes << std::endl; + } + //create the usrp2 implementation guts return device::sptr( new usrp2_impl(ctrl_transport, data_transport) |