summaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/device.cpp11
-rw-r--r--host/lib/transport/udp_zero_copy_asio.cpp32
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp23
3 files changed, 39 insertions, 27 deletions
diff --git a/host/lib/device.cpp b/host/lib/device.cpp
index 706f64951..88bd2cff4 100644
--- a/host/lib/device.cpp
+++ b/host/lib/device.cpp
@@ -97,11 +97,6 @@ device::sptr device::make(const device_addr_t &hint, size_t which){
BOOST_FOREACH(const dev_fcn_reg_t &fcn, get_dev_fcn_regs()){
BOOST_FOREACH(device_addr_t dev_addr, fcn.get<0>()(hint)){
- //copy keys that were in hint but not in dev_addr
- //this way, we can pass additional transport arguments
- BOOST_FOREACH(const std::string &key, hint.keys()){
- if (not dev_addr.has_key(key)) dev_addr[key] = hint[key];
- }
//append the discovered address and its factory function
dev_addr_makers.push_back(dev_addr_make_t(dev_addr, fcn.get<1>()));
}
@@ -127,6 +122,12 @@ device::sptr device::make(const device_addr_t &hint, size_t which){
size_t dev_hash = hash_device_addr(dev_addr);
//std::cout << boost::format("Hash: %u") % dev_hash << std::endl;
+ //copy keys that were in hint but not in dev_addr
+ //this way, we can pass additional transport arguments
+ BOOST_FOREACH(const std::string &key, hint.keys()){
+ if (not dev_addr.has_key(key)) dev_addr[key] = hint[key];
+ }
+
//map device address hash to created devices
static uhd::dict<size_t, boost::weak_ptr<device> > hash_to_device;
diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp
index 7e643abad..09386a60c 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 resize_recv_buff_size(size_t num_bytes);
+ size_t resize_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,18 @@ 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;
+size_t udp_zero_copy_impl::resize_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);
+size_t udp_zero_copy_impl::resize_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..2b974fb9b 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>
@@ -50,7 +51,7 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){
if (if_addrs.inet == asio::ip::address_v4::loopback().to_string()) continue;
//create a new hint with this broadcast address
- device_addr_t new_hint = hint;
+ device_addr_t new_hint;
new_hint["addr"] = if_addrs.bcast;
//call discover with the new hint and append results
@@ -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->resize_recv_buff_size(num_byes);
+ if (num_byes != actual_bytes) std::cout << boost::format(
+ "Target recv buffer size: %d\n"
+ "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->resize_send_buff_size(num_byes);
+ if (num_byes != actual_bytes) std::cout << boost::format(
+ "Target send buffer size: %d\n"
+ "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)