.. _program_listing_file_BackendLibfabric_Helpers.hpp: Program Listing for File Helpers.hpp ==================================== |exhale_lsh| :ref:`Return to documentation for file ` (``BackendLibfabric/Helpers.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef NETIO3BACKEND_BACKENDLIBFABRIC_HELPERS_HPP #define NETIO3BACKEND_BACKENDLIBFABRIC_HELPERS_HPP #include #include #include #include "netio3-backend/Netio3Backend.hpp" #include "netio3-backend/Issues.hpp" namespace netio3::libfabric { struct CqCmFds { int cq_fd; int cm_fd; }; struct FiInfoDeleter { void operator()(fi_info* info) const { if (info != nullptr) { fi_freeinfo(info); } } }; template concept HasFidConcept = requires(T obj) { { obj.fid }; }; template class FiCloseDeleter { public: explicit FiCloseDeleter(EndPointAddress address = {}, std::string message = "") : m_address{std::move(address)}, m_message{std::move(message)} {} void operator()(T* obj) const { if (obj != nullptr) { const auto ret = fi_close(&obj->fid); if (ret != FI_SUCCESS) { ers::error(FailedCloseEndpoint( ERS_HERE, m_address.address(), m_address.port(), std::format("{}, error {} - {}", m_message, ret, fi_strerror(-ret)))); } } } private: EndPointAddress m_address; std::string m_message; }; using FiInfoUniquePtr = std::unique_ptr; template using FiCloseUniquePtr = std::unique_ptr>; class FiInfoWrapper { public: FiInfoWrapper() : m_info{fi_allocinfo()} {} [[nodiscard]] fi_info* get() const { return m_info.get(); } private: FiInfoUniquePtr m_info{nullptr}; }; static constexpr std::size_t MAX_CQ_EVENTS = 10; static constexpr int MAX_CQ_ENTRIES = 4096; struct Endpoint { FiInfoUniquePtr fi{nullptr}; FiCloseUniquePtr rcq{nullptr}; FiCloseUniquePtr cq{nullptr}; FiCloseUniquePtr eq{nullptr}; FiCloseUniquePtr ep{nullptr}; int eqfd{-1}; int cqfd{-1}; std::size_t cq_size{MAX_CQ_EVENTS}; }; [[nodiscard]] std::string get_provider(NetworkMode mode); [[nodiscard]] EndPointAddress peer_address(fid_ep* ep); } // namespace netio3::libfabric #endif // NETIO3BACKEND_BACKENDLIBFABRIC_HELPERS_HPP