.. _program_listing_file_BackendAsyncmsg_Buffer.hpp: Program Listing for File Buffer.hpp =================================== |exhale_lsh| :ref:`Return to documentation for file ` (``BackendAsyncmsg/Buffer.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef NETIO3BACKEND_BACKENDASYNCMSG_BUFFER_HPP #define NETIO3BACKEND_BACKENDASYNCMSG_BUFFER_HPP #include #include #include #include "netio3-backend/NetworkBuffer.hpp" #include "netio3-backend/Netio3Backend.hpp" ERS_DECLARE_ISSUE(netio3, TcpNoBuffers, "No buffers allocated", ) // cppcheck-suppress syntaxError namespace netio3::asyncmsg { using Key = std::uint64_t; class Buffer : public NetworkBuffer { public: Buffer(const std::size_t size, const Key key) : NetworkBuffer(size), m_key{key} {} [[nodiscard]] Key getKey() const { return m_key; } private: Key m_key{}; }; class BufferManager { public: explicit BufferManager(const ConnectionParameters& params); [[nodiscard]] NetworkBuffer* getBuffer(); void returnBuffer(const NetworkBuffer* buffer); void returnBuffer(Key key); [[nodiscard]] std::size_t getNumAvailableBuffers(); private: [[nodiscard]] static std::map initBuffers(const ConnectionParameters& params); std::map m_buffers; tbb::concurrent_bounded_queue m_availableBuffers; std::atomic m_minNumAvailableBuffers{0}; }; } // namespace netio3::asyncmsg #endif // NETIO3BACKEND_BACKENDASYNCMSG_BUFFER_HPP