MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
Fabric.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#include "Fabric.hpp"
6#include <memory>
7#include <rdma/fabric.h>
8#include <rdma/fi_errno.h>
9#include "Exception.hpp"
10#include "FabricInfo.hpp"
11
13{
14
15 std::shared_ptr<Fabric> Fabric::open(FabricInfoView info)
16 {
17 ::fid_fabric* fid;
18
19 fiCall(::fi_fabric2, "Failed to open fabric", info.raw(), &fid, 0, nullptr);
20
21 // expose the private constructor to std::make_shared inside this function
22 struct MakeSharedEnabler : public Fabric
23 {
24 MakeSharedEnabler(::fid_fabric* raw, FabricInfoView info)
25 : Fabric(raw, info)
26 {}
27 };
28
29 return std::make_shared<MakeSharedEnabler>(fid, info);
30 }
31
33 : _raw(raw)
34 , _info(info.owned())
35 {}
36
38 {
39 catchAndLogFabricError([this]() { close(); }, "Failed to close fabrics");
40 }
41
42 Fabric::Fabric(Fabric&& other) noexcept
43 : _raw(other._raw)
44 , _info(other._info)
45 {
46 other._raw = nullptr;
47 }
48
50 {
51 close();
52
53 _raw = other._raw;
54 _info = other._info;
55 other._raw = nullptr;
56
57 return *this;
58 }
59
60 ::fid_fabric* Fabric::raw() noexcept
61 {
62 return _raw;
63 }
64
65 ::fid_fabric const* Fabric::raw() const noexcept
66 {
67 return _raw;
68 }
69
71 {
72 return _info.view();
73 }
74
76 {
77 if (_raw != nullptr)
78 {
79 fiCall(::fi_close, "failed to close fabric", &_raw->fid);
80 }
81 }
82
83}
Non-owning view of a FabricInfo. Returned when iterating over a FabricInfoList.
Fabric(Fabric const &)=delete
void close()
Close the underlying fabric object.
Definition Fabric.cpp:75
static std::shared_ptr< Fabric > open(FabricInfoView info)
Open a fabric object based on the provided FabricInfoView.
Definition Fabric.cpp:15
void operator=(Fabric const &)=delete
::fid_fabric * raw() noexcept
Mutable accessor for the underlying raw libfabric fabric object.
Definition Fabric.cpp:60
FabricInfoView info() const noexcept
Get a view on the libfabric info used to open this fabric.
Definition Fabric.cpp:70
void catchAndLogFabricError(F &&fun, std::string_view msg)
int fiCall(F &&fun, std::string_view msg, T &&... args)
Call a libfabric function and check its return code.