aboutsummaryrefslogtreecommitdiffstats
path: root/host/include/uhd/transport/zero_copy.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'host/include/uhd/transport/zero_copy.hpp')
-rw-r--r--host/include/uhd/transport/zero_copy.hpp264
1 files changed, 175 insertions, 89 deletions
diff --git a/host/include/uhd/transport/zero_copy.hpp b/host/include/uhd/transport/zero_copy.hpp
index 52c6d4143..2815e3189 100644
--- a/host/include/uhd/transport/zero_copy.hpp
+++ b/host/include/uhd/transport/zero_copy.hpp
@@ -19,115 +19,201 @@
#define INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP
#include <uhd/config.hpp>
+#include <uhd/utils/pimpl.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
namespace uhd{ namespace transport{
-/*!
- * A managed receive buffer:
- * Contains a reference to transport-managed memory,
- * and a method to release the memory after reading.
- */
-class UHD_API managed_recv_buffer : boost::noncopyable{
-public:
- typedef boost::shared_ptr<managed_recv_buffer> sptr;
-
- /*!
- * Managed recv buffer destructor:
- * Signal to the transport that we are done with the buffer.
- * This should be called to release the buffer to the transport.
- * After calling, the referenced memory should be considered invalid.
- */
- virtual ~managed_recv_buffer(void){};
-
- /*!
- * Get the size of the underlying buffer.
- * \return the number of bytes
- */
- size_t size(void) const{
- return boost::asio::buffer_size(this->get());
- }
-
- /*!
- * Get a pointer to the underlying buffer.
- * \return a pointer into memory
- */
- template <class T> T cast(void) const{
- return boost::asio::buffer_cast<T>(this->get());
- }
-
-private:
- /*!
- * Get a reference to the internal const buffer.
- * The buffer has a reference to memory and a size.
- * \return a boost asio const buffer
- */
- virtual const boost::asio::const_buffer &get(void) const = 0;
-};
-
-/*!
- * A managed send buffer:
- * Contains a reference to transport-managed memory,
- * and a method to release the memory after writing.
- */
-class UHD_API managed_send_buffer : boost::noncopyable{
-public:
- typedef boost::shared_ptr<managed_send_buffer> sptr;
-
- /*!
- * Signal to the transport that we are done with the buffer.
- * This should be called to commit the write to the transport object.
- * After calling, the referenced memory should be considered invalid.
- * \param num_bytes the number of bytes written into the buffer
- */
- virtual void commit(size_t num_bytes) = 0;
-
/*!
- * Get the size of the underlying buffer.
- * \return the number of bytes
+ * A managed receive buffer:
+ * Contains a reference to transport-managed memory,
+ * and a method to release the memory after reading.
*/
- size_t size(void) const{
- return boost::asio::buffer_size(this->get());
- }
+ class UHD_API managed_recv_buffer : boost::noncopyable{
+ public:
+ typedef boost::shared_ptr<managed_recv_buffer> sptr;
+
+ /*!
+ * Managed recv buffer destructor:
+ * Signal to the transport that we are done with the buffer.
+ * This should be called to release the buffer to the transport.
+ * After calling, the referenced memory should be considered invalid.
+ */
+ virtual ~managed_recv_buffer(void) = 0;
+
+ /*!
+ * Get the size of the underlying buffer.
+ * \return the number of bytes
+ */
+ size_t size(void) const{
+ return boost::asio::buffer_size(this->get());
+ }
+
+ /*!
+ * Get a pointer to the underlying buffer.
+ * \return a pointer into memory
+ */
+ template <class T> T cast(void) const{
+ return boost::asio::buffer_cast<T>(this->get());
+ }
+
+ private:
+ /*!
+ * Get a reference to the internal const buffer.
+ * The buffer has a reference to memory and a size.
+ * \return a boost asio const buffer
+ */
+ virtual const boost::asio::const_buffer &get(void) const = 0;
+ };
/*!
- * Get a pointer to the underlying buffer.
- * \return a pointer into memory
+ * A managed send buffer:
+ * Contains a reference to transport-managed memory,
+ * and a method to release the memory after writing.
*/
- template <class T> T cast(void) const{
- return boost::asio::buffer_cast<T>(this->get());
- }
+ class UHD_API managed_send_buffer : boost::noncopyable{
+ public:
+ typedef boost::shared_ptr<managed_send_buffer> sptr;
+
+ /*!
+ * Signal to the transport that we are done with the buffer.
+ * This should be called to commit the write to the transport object.
+ * After calling, the referenced memory should be considered invalid.
+ * \param num_bytes the number of bytes written into the buffer
+ */
+ virtual void commit(size_t num_bytes) = 0;
+
+ /*!
+ * Get the size of the underlying buffer.
+ * \return the number of bytes
+ */
+ size_t size(void) const{
+ return boost::asio::buffer_size(this->get());
+ }
+
+ /*!
+ * Get a pointer to the underlying buffer.
+ * \return a pointer into memory
+ */
+ template <class T> T cast(void) const{
+ return boost::asio::buffer_cast<T>(this->get());
+ }
+
+ private:
+ /*!
+ * Get a reference to the internal mutable buffer.
+ * The buffer has a reference to memory and a size.
+ * \return a boost asio mutable buffer
+ */
+ virtual const boost::asio::mutable_buffer &get(void) const = 0;
+ };
-private:
/*!
- * Get a reference to the internal mutable buffer.
- * The buffer has a reference to memory and a size.
- * \return a boost asio mutable buffer
+ * A zero-copy interface for transport objects.
+ * Provides a way to get send and receive buffers
+ * with memory managed by the transport object.
*/
- virtual const boost::asio::mutable_buffer &get(void) const = 0;
-};
-
-/*!
- * A zero-copy interface for transport objects.
- * Provides a way to get send and receive buffers
- * with memory managed by the transport object.
- */
-class UHD_API zero_copy_if : boost::noncopyable{
-public:
- typedef boost::shared_ptr<zero_copy_if> sptr;
+ class UHD_API zero_copy_if : boost::noncopyable{
+ public:
+ typedef boost::shared_ptr<zero_copy_if> sptr;
+
+ /*!
+ * Get a new receive buffer from this transport object.
+ */
+ virtual managed_recv_buffer::sptr get_recv_buff(void) = 0;
+
+ /*!
+ * Get the maximum number of receive frames:
+ * The maximum number of valid managed recv buffers,
+ * or the maximum number of frames in the ring buffer,
+ * depending upon the underlying implementation.
+ * \return number of frames
+ */
+ virtual size_t get_num_recv_frames(void) const = 0;
+
+ /*!
+ * Get a new send buffer from this transport object.
+ */
+ virtual managed_send_buffer::sptr get_send_buff(void) = 0;
+
+ /*!
+ * Get the maximum number of send frames:
+ * The maximum number of valid managed send buffers,
+ * or the maximum number of frames in the ring buffer,
+ * depending upon the underlying implementation.
+ * \return number of frames
+ */
+ virtual size_t get_num_send_frames(void) const = 0;
+
+ };
/*!
- * Get a new receive buffer from this transport object.
+ * A phony-zero-copy interface for transport objects that
+ * provides a zero-copy interface on top of copying transport.
+ * This interface implements the get managed recv buffer,
+ * the base class must implement the private recv method.
*/
- virtual managed_recv_buffer::sptr get_recv_buff(void) = 0;
+ class UHD_API phony_zero_copy_recv_if : public virtual zero_copy_if{
+ public:
+ /*!
+ * Create a phony zero copy recv interface.
+ * \param max_buff_size max buffer size in bytes
+ */
+ phony_zero_copy_recv_if(size_t max_buff_size);
+
+ //! destructor
+ virtual ~phony_zero_copy_recv_if(void);
+
+ /*!
+ * Get a new receive buffer from this transport object.
+ */
+ managed_recv_buffer::sptr get_recv_buff(void);
+
+ private:
+ /*!
+ * Perform a private copying recv.
+ * \param buff the buffer to write data into
+ * \return the number of bytes written to buff
+ */
+ virtual size_t recv(const boost::asio::mutable_buffer &buff) = 0;
+
+ UHD_PIMPL_DECL(impl) _impl;
+ };
/*!
- * Get a new send buffer from this transport object.
+ * A phony-zero-copy interface for transport objects that
+ * provides a zero-copy interface on top of copying transport.
+ * This interface implements the get managed send buffer,
+ * the base class must implement the private send method.
*/
- virtual managed_send_buffer::sptr get_send_buff(void) = 0;
-};
+ class UHD_API phony_zero_copy_send_if : public virtual zero_copy_if{
+ public:
+ /*!
+ * Create a phony zero copy send interface.
+ * \param max_buff_size max buffer size in bytes
+ */
+ phony_zero_copy_send_if(size_t max_buff_size);
+
+ //! destructor
+ virtual ~phony_zero_copy_send_if(void);
+
+ /*!
+ * Get a new send buffer from this transport object.
+ */
+ managed_send_buffer::sptr get_send_buff(void);
+
+ private:
+ /*!
+ * Perform a private copying send.
+ * \param buff the buffer to read data from
+ * \return the number of bytes read from buff
+ */
+ virtual size_t send(const boost::asio::const_buffer &buff) = 0;
+
+ UHD_PIMPL_DECL(impl) _impl;
+ };
}} //namespace