MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
mxl::lib::fabrics::ofi::PassiveEndpoint Class Reference

RAII Wrapper around a libfabric passive endpoint (fid_pep). More...

#include <PassiveEndpoint.hpp>

Public Member Functions

void bind (std::shared_ptr< EventQueue > eq)
 Bind the endpoint to an event queue.
std::shared_ptr< EventQueue > eventQueue () const
 Accessor for the associated event queue.
Endpoint::Id id () const noexcept
 Get the endpoints id.
void listen ()
 Put the passive endpoint into listening mode.
RawFabricAddress localAddress ()
 Obtain the local fabric address for this passive endpoint.
PassiveEndpoint & operator= (PassiveEndpoint &&)
void operator= (PassiveEndpoint const &)=delete
 PassiveEndpoint (PassiveEndpoint &&) noexcept
 PassiveEndpoint (PassiveEndpoint const &)=delete
::fid_pep const * raw () const noexcept
 Access the underlying raw fid_pep pointer.
::fid_pep * raw () noexcept
 Access the underlying raw fid_pep pointer.
void reject (Event &entry)
 Reject a connection request event.
 ~PassiveEndpoint ()

Static Public Member Functions

static PassiveEndpoint create (std::shared_ptr< Fabric > fabric)
 Allocate a new PassiveEndpoint associated with the given Fabric.
static PassiveEndpoint create (std::shared_ptr< Fabric > fabric, Endpoint::Id id)
 Allocate a new PassiveEndpoint associated with the given Fabric.

Private Member Functions

void close ()
 Releases all underlying resources. This is called from the destructor and the move-assignment operator.
 PassiveEndpoint (::fid_pep *raw, std::shared_ptr< Fabric > fabric, Endpoint::Id id, std::optional< std::shared_ptr< EventQueue > > eq=std::nullopt)
 Construct the PassiveEndpoint.

Private Attributes

std::optional< std::shared_ptr< EventQueue > > _eq
std::shared_ptr< Fabric > _fabric
Endpoint::Id _id
::fid_pep * _raw

Detailed Description

RAII Wrapper around a libfabric passive endpoint (fid_pep).

A passive endpoint can be viewed like a bound TCP socket listening for incoming connections.

Definition at line 20 of file PassiveEndpoint.hpp.

Constructor & Destructor Documentation

◆ ~PassiveEndpoint()

mxl::lib::fabrics::ofi::PassiveEndpoint::~PassiveEndpoint ( )

Definition at line 29 of file PassiveEndpoint.cpp.

30 {
31 catchAndLogFabricError([this]() { close(); }, "Failed to close passive endpoint");
32 }
void close()
Releases all underlying resources. This is called from the destructor and the move-assignment operato...
void catchAndLogFabricError(F &&fun, std::string_view msg)

◆ PassiveEndpoint() [1/3]

mxl::lib::fabrics::ofi::PassiveEndpoint::PassiveEndpoint ( PassiveEndpoint const & )
delete

◆ PassiveEndpoint() [2/3]

mxl::lib::fabrics::ofi::PassiveEndpoint::PassiveEndpoint ( PassiveEndpoint && other)
noexcept

Definition at line 55 of file PassiveEndpoint.cpp.

56 : _raw(other._raw)
57 , _fabric(std::move(other._fabric))
58 , _id(other._id)
59 , _eq(std::move(other._eq))
60 {
61 other._raw = nullptr;
62 }
std::optional< std::shared_ptr< EventQueue > > _eq

◆ PassiveEndpoint() [3/3]

mxl::lib::fabrics::ofi::PassiveEndpoint::PassiveEndpoint ( ::fid_pep * raw,
std::shared_ptr< Fabric > fabric,
Endpoint::Id id,
std::optional< std::shared_ptr< EventQueue > > eq = std::nullopt )
private

Construct the PassiveEndpoint.

Parameters
rawThe raw libfabric fid_pep pointer.
fabricThe Fabric the passive endpoint is associated with.
eqOptional event queue associated with the passive endpoint.

Definition at line 34 of file PassiveEndpoint.cpp.

35 : _raw(raw)
36 , _fabric(std::move(fabric))
37 , _id(id)
38 , _eq(std::move(eq))
39 {}
::fid_pep * raw() noexcept
Access the underlying raw fid_pep pointer.

Member Function Documentation

◆ bind()

void mxl::lib::fabrics::ofi::PassiveEndpoint::bind ( std::shared_ptr< EventQueue > eq)

Bind the endpoint to an event queue.

The endpoint can be bound to an event queue only once. The Endpoint object will take ownership of an instance of the shared pointer, so the queue can not be destroyed before the endpoint.

Parameters
eqThe event queue to bind to the endpoint.

Definition at line 82 of file PassiveEndpoint.cpp.

83 {
84 fiCall(::fi_pep_bind, "Failed to bind event queue to passive endpoint", _raw, &eq->raw()->fid, 0);
85
86 _eq = eq;
87 }
int fiCall(F &&fun, std::string_view msg, T &&... args)
Call a libfabric function and check its return code.

◆ close()

void mxl::lib::fabrics::ofi::PassiveEndpoint::close ( )
private

Releases all underlying resources. This is called from the destructor and the move-assignment operator.

Definition at line 46 of file PassiveEndpoint.cpp.

47 {
48 if (_raw)
49 {
50 fiCall(::fi_close, "Failed to close passive endpoint", &_raw->fid);
51 _raw = nullptr;
52 }
53 }

◆ create() [1/2]

PassiveEndpoint mxl::lib::fabrics::ofi::PassiveEndpoint::create ( std::shared_ptr< Fabric > fabric)
staticnodiscard

Allocate a new PassiveEndpoint associated with the given Fabric.

Parameters
fabricThe Fabric to create the PassiveEndpoint on.
Returns
A new PassiveEndpoint object.

Definition at line 24 of file PassiveEndpoint.cpp.

25 {
26 return PassiveEndpoint::create(std::move(fabric), Endpoint::randomId());
27 }
static Id randomId() noexcept
Generate a new random endpoint id.
Definition Endpoint.cpp:32
static PassiveEndpoint create(std::shared_ptr< Fabric > fabric)
Allocate a new PassiveEndpoint associated with the given Fabric.

◆ create() [2/2]

PassiveEndpoint mxl::lib::fabrics::ofi::PassiveEndpoint::create ( std::shared_ptr< Fabric > fabric,
Endpoint::Id id )
staticnodiscard

Allocate a new PassiveEndpoint associated with the given Fabric.

Parameters
fabricThe Fabric to create the PassiveEndpoint on.
Returns
A new PassiveEndpoint object.

Definition at line 15 of file PassiveEndpoint.cpp.

16 {
17 ::fid_pep* pep;
18
19 fiCall(::fi_passive_ep, "Failed to create passive endpoint", fabric->raw(), fabric->info().raw(), &pep, nullptr);
20
21 return {pep, fabric, id, std::nullopt};
22 }
Endpoint::Id id() const noexcept
Get the endpoints id.

◆ eventQueue()

std::shared_ptr< EventQueue > mxl::lib::fabrics::ofi::PassiveEndpoint::eventQueue ( ) const
nodiscard

Accessor for the associated event queue.

If an event queue is associated with this endpoint. Get the queue. Throws an exception if no event queue is associated with this endpoint.

Definition at line 106 of file PassiveEndpoint.cpp.

107 {
108 if (!_eq)
109 {
110 throw Exception::internal("No event queue bound to this endpoint");
111 }
112
113 return *_eq;
114 }
static Exception internal(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INTERNAL exception.
Definition Exception.hpp:51

◆ id()

Endpoint::Id mxl::lib::fabrics::ofi::PassiveEndpoint::id ( ) const
nodiscardnoexcept

Get the endpoints id.

Definition at line 41 of file PassiveEndpoint.cpp.

42 {
43 return _id;
44 }

◆ listen()

void mxl::lib::fabrics::ofi::PassiveEndpoint::listen ( )

Put the passive endpoint into listening mode.

Definition at line 89 of file PassiveEndpoint.cpp.

90 {
91 fiCall(::fi_listen, "Failed to transition the endpoint into listener mode", _raw);
92 }

◆ localAddress()

RawFabricAddress mxl::lib::fabrics::ofi::PassiveEndpoint::localAddress ( )
inlinenodiscard

Obtain the local fabric address for this passive endpoint.

Definition at line 84 of file PassiveEndpoint.hpp.

85 {
86 return RawFabricAddress::fromFid(&_raw->fid, _fabric->info());
87 }
static RawFabricAddress fromFid(::fid_t fid, FabricInfoView info)
Retrieve the fabric address of an endpoint by passing its fid.
Definition Address.cpp:27

◆ operator=() [1/2]

PassiveEndpoint & mxl::lib::fabrics::ofi::PassiveEndpoint::operator= ( PassiveEndpoint && other)

Definition at line 64 of file PassiveEndpoint.cpp.

65 {
66 catchAndLogFabricError([this]() { close(); }, "Failed to close passive endpoint");
67
68 _raw = other._raw;
69 _id = other._id;
70 other._raw = nullptr;
71 other._id = 0;
72
73 static_assert(std::is_nothrow_move_assignable_v<decltype(other._fabric)>, "Member must be nothrow move assignable");
74 static_assert(std::is_nothrow_move_assignable_v<decltype(other._eq)>, "Member must be nothrow move assignable");
75
76 _fabric = std::move(other._fabric);
77 _eq = std::move(other._eq);
78
79 return *this;
80 }

◆ operator=() [2/2]

void mxl::lib::fabrics::ofi::PassiveEndpoint::operator= ( PassiveEndpoint const & )
delete

◆ raw() [1/2]

fid_pep const * mxl::lib::fabrics::ofi::PassiveEndpoint::raw ( ) const
nodiscardnoexcept

Access the underlying raw fid_pep pointer.

Definition at line 121 of file PassiveEndpoint.cpp.

122 {
123 return _raw;
124 }

◆ raw() [2/2]

fid_pep * mxl::lib::fabrics::ofi::PassiveEndpoint::raw ( )
nodiscardnoexcept

Access the underlying raw fid_pep pointer.

Definition at line 116 of file PassiveEndpoint.cpp.

117 {
118 return _raw;
119 }

◆ reject()

void mxl::lib::fabrics::ofi::PassiveEndpoint::reject ( Event & entry)

Reject a connection request event.

Parameters
entryThe event entry representing the connection request to reject.

Definition at line 94 of file PassiveEndpoint.cpp.

95 {
96 auto fid = entry.fid();
97 if (!fid)
98 {
99 MXL_ERROR("Cannot reject a connection notification entry without a fid");
100 return;
101 }
102
103 fiCall(::fi_reject, "Failed to reject connection request", _raw, fid, nullptr, 0);
104 }
#define MXL_ERROR(...)
Definition Logging.hpp:67

Member Data Documentation

◆ _eq

std::optional<std::shared_ptr<EventQueue> > mxl::lib::fabrics::ofi::PassiveEndpoint::_eq
private

Event queue lives here after PassiveEndpoint::bind()

Definition at line 117 of file PassiveEndpoint.hpp.

◆ _fabric

std::shared_ptr<Fabric> mxl::lib::fabrics::ofi::PassiveEndpoint::_fabric
private

Pointer to the fabric for which the passive endpoint was created.

Definition at line 114 of file PassiveEndpoint.hpp.

◆ _id

Endpoint::Id mxl::lib::fabrics::ofi::PassiveEndpoint::_id
private

Definition at line 115 of file PassiveEndpoint.hpp.

◆ _raw

::fid_pep* mxl::lib::fabrics::ofi::PassiveEndpoint::_raw
private

Raw resource reference

Definition at line 113 of file PassiveEndpoint.hpp.


The documentation for this class was generated from the following files: