summaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-04-30 12:22:23 -0700
committerJosh Blum <josh@joshknows.com>2010-04-30 12:22:23 -0700
commitdd8373063684418eb978cdd1a2b0896923ba1d47 (patch)
treecc4503df0f783b5a7027b03a409ad29a3a271f9a /host/lib
parent04dae4bf6b11b5aad383f95be6a77863a7c2f6ec (diff)
downloaduhd-dd8373063684418eb978cdd1a2b0896923ba1d47.tar.gz
uhd-dd8373063684418eb978cdd1a2b0896923ba1d47.tar.bz2
uhd-dd8373063684418eb978cdd1a2b0896923ba1d47.zip
made buffer size args part of constructor
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/transport/udp_zero_copy_asio.cpp57
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp32
2 files changed, 51 insertions, 38 deletions
diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp
index 09386a60c..ee44803f4 100644
--- a/host/lib/transport/udp_zero_copy_asio.cpp
+++ b/host/lib/transport/udp_zero_copy_asio.cpp
@@ -19,6 +19,8 @@
#include <boost/cstdint.hpp>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
+#include <boost/format.hpp>
+#include <iostream>
using namespace uhd::transport;
@@ -103,8 +105,18 @@ public:
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);
+ size_t resize_recv_buff(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();
+ }
+ size_t resize_send_buff(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();
+ }
private:
boost::asio::ip::udp::socket *_socket;
@@ -157,25 +169,34 @@ managed_send_buffer::sptr udp_zero_copy_impl::get_send_buff(void){
);
}
-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();
-}
-
-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();
-}
-
/***********************************************************************
* UDP zero copy make function
**********************************************************************/
udp_zero_copy::sptr udp_zero_copy::make(
- const std::string &addr, const std::string &port
+ const std::string &addr,
+ const std::string &port,
+ size_t recv_buff_size,
+ size_t send_buff_size
){
- return sptr(new udp_zero_copy_impl(addr, port));
+ boost::shared_ptr<udp_zero_copy_impl> udp_trans(new udp_zero_copy_impl(addr, port));
+
+ //resize the recv buffer if size was provided
+ if (recv_buff_size > 0){
+ size_t actual_bytes = udp_trans->resize_recv_buff(recv_buff_size);
+ if (recv_buff_size != actual_bytes) std::cout << boost::format(
+ "Target recv buffer size: %d\n"
+ "Actual recv byffer size: %d"
+ ) % recv_buff_size % actual_bytes << std::endl;
+ }
+
+ //resize the send buffer if size was provided
+ if (send_buff_size > 0){
+ size_t actual_bytes = udp_trans->resize_send_buff(send_buff_size);
+ if (send_buff_size != actual_bytes) std::cout << boost::format(
+ "Target send buffer size: %d\n"
+ "Actual send byffer size: %d"
+ ) % send_buff_size % actual_bytes << std::endl;
+ }
+
+ return udp_trans;
}
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index 2b974fb9b..1dde8c054 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -113,31 +113,23 @@ device::sptr usrp2::make(const device_addr_t &device_addr){
device_addr["addr"], num2str(USRP2_UDP_CTRL_PORT)
);
- //create a data transport
- udp_zero_copy::sptr data_transport = udp_zero_copy::make(
- device_addr["addr"], num2str(USRP2_UDP_DATA_PORT)
- );
-
- //resize the recv data transport buffers
+ //extract the receive and send buffer sizes
+ size_t recv_buff_size = 0, send_buff_size= 0 ;
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;
+ recv_buff_size = size_t(boost::lexical_cast<double>(device_addr["recv_buff_size"]));
}
-
- //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;
+ send_buff_size = size_t(boost::lexical_cast<double>(device_addr["send_buff_size"]));
}
+ //create a data transport
+ udp_zero_copy::sptr data_transport = udp_zero_copy::make(
+ device_addr["addr"],
+ num2str(USRP2_UDP_DATA_PORT),
+ recv_buff_size,
+ send_buff_size
+ );
+
//create the usrp2 implementation guts
return device::sptr(
new usrp2_impl(ctrl_transport, data_transport)