aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-06-01 15:01:01 -0700
committerJosh Blum <josh@joshknows.com>2010-06-01 15:01:01 -0700
commitf78cae4911148470f1b5fbf2ff8ea795250419a1 (patch)
treeceaeeb4e26c1440876222a41382a482a2112e2d2 /host/lib
parentbb1eef8cade6e39532919918ce1168c3e62a54df (diff)
parent0b609f776494ecff50c7a2a4d9880d3186fe2421 (diff)
downloaduhd-f78cae4911148470f1b5fbf2ff8ea795250419a1.tar.gz
uhd-f78cae4911148470f1b5fbf2ff8ea795250419a1.tar.bz2
uhd-f78cae4911148470f1b5fbf2ff8ea795250419a1.zip
Merge branch 'buffer' of ettus.sourcerepo.com:ettus/uhdpriv into buffer
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/transport/udp_zero_copy_asio.cpp85
1 files changed, 49 insertions, 36 deletions
diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp
index 0c604811a..4402437f3 100644
--- a/host/lib/transport/udp_zero_copy_asio.cpp
+++ b/host/lib/transport/udp_zero_copy_asio.cpp
@@ -46,12 +46,42 @@ class udp_zero_copy_impl:
public:
typedef boost::shared_ptr<udp_zero_copy_impl> sptr;
- //structors
- udp_zero_copy_impl(const std::string &addr, const std::string &port);
- ~udp_zero_copy_impl(void);
+ udp_zero_copy_impl(
+ const std::string &addr,
+ const std::string &port
+ ):
+ phony_zero_copy_recv_if(MAX_DGRAM_SIZE),
+ phony_zero_copy_send_if(MAX_DGRAM_SIZE)
+ {
+ //std::cout << boost::format("Creating udp transport for %s %s") % addr % port << std::endl;
+
+ // resolve the address
+ boost::asio::ip::udp::resolver resolver(_io_service);
+ boost::asio::ip::udp::resolver::query query(boost::asio::ip::udp::v4(), addr, port);
+ boost::asio::ip::udp::endpoint receiver_endpoint = *resolver.resolve(query);
+
+ // create, open, and connect the socket
+ _socket = new boost::asio::ip::udp::socket(_io_service);
+ _socket->open(boost::asio::ip::udp::v4());
+ _socket->connect(receiver_endpoint);
+
+ // set recv timeout
+ timeval tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = size_t(RECV_TIMEOUT*1e6);
+ UHD_ASSERT_THROW(setsockopt(
+ _socket->native(),
+ SOL_SOCKET, SO_RCVTIMEO,
+ (const char *)&tv, sizeof(timeval)
+ ) == 0);
+ }
+
+ ~udp_zero_copy_impl(void){
+ delete _socket;
+ }
//get size for internal socket buffer
- template <typename Opt> size_t get_buff_size(void){
+ template <typename Opt> size_t get_buff_size(void) const{
Opt option;
_socket->get_option(option);
return option.value();
@@ -64,6 +94,20 @@ public:
return get_buff_size<Opt>();
}
+
+ //The number of frames is approximately the buffer size divided by the max datagram size.
+ //In reality, this is a phony zero-copy interface and the number of frames is infinite.
+ //However, its sensible to advertise a frame count that is approximate to buffer size.
+ //This way, the transport caller will have an idea about how much buffering to create.
+
+ size_t get_num_recv_frames(void) const{
+ return this->get_buff_size<boost::asio::socket_base::receive_buffer_size>()/MAX_DGRAM_SIZE;
+ }
+
+ size_t get_num_send_frames(void) const{
+ return this->get_buff_size<boost::asio::socket_base::send_buffer_size>()/MAX_DGRAM_SIZE;
+ }
+
private:
boost::asio::ip::udp::socket *_socket;
boost::asio::io_service _io_service;
@@ -77,41 +121,10 @@ private:
}
};
-udp_zero_copy_impl::udp_zero_copy_impl(const std::string &addr, const std::string &port):
- phony_zero_copy_recv_if(MAX_DGRAM_SIZE),
- phony_zero_copy_send_if(MAX_DGRAM_SIZE)
-{
- //std::cout << boost::format("Creating udp transport for %s %s") % addr % port << std::endl;
-
- // resolve the address
- boost::asio::ip::udp::resolver resolver(_io_service);
- boost::asio::ip::udp::resolver::query query(boost::asio::ip::udp::v4(), addr, port);
- boost::asio::ip::udp::endpoint receiver_endpoint = *resolver.resolve(query);
-
- // create, open, and connect the socket
- _socket = new boost::asio::ip::udp::socket(_io_service);
- _socket->open(boost::asio::ip::udp::v4());
- _socket->connect(receiver_endpoint);
-
- // set recv timeout
- timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = size_t(RECV_TIMEOUT*1e6);
- UHD_ASSERT_THROW(setsockopt(
- _socket->native(),
- SOL_SOCKET, SO_RCVTIMEO,
- (const char *)&tv, sizeof(timeval)
- ) == 0);
-}
-
-udp_zero_copy_impl::~udp_zero_copy_impl(void){
- delete _socket;
-}
-
/***********************************************************************
* UDP zero copy make function
**********************************************************************/
-template<typename Opt> static inline void resize_buff_helper(
+template<typename Opt> static void resize_buff_helper(
udp_zero_copy_impl::sptr udp_trans,
size_t target_size,
const std::string &name