12#include <rdma/fi_eq.h>
13#include <rdma/fi_errno.h>
31 raw.wait_obj = FI_WAIT_UNSPEC;
32 raw.wait_set =
nullptr;
34 raw.signaling_vector = 0;
41 auto eq_attr = attr.
raw();
43 fiCall(::fi_eq_open,
"Failed to open event queue", fabric->raw(), &eq_attr, &eq,
nullptr);
48 MakeSharedEnabler(::fid_eq*
raw, std::shared_ptr<Fabric> fabric)
53 return std::make_shared<MakeSharedEnabler>(eq, fabric);
58 std::uint32_t eventType;
61 auto const ret = fi_eq_read(
_raw, &eventType, &entry,
sizeof(entry), 0);
68 auto timeoutMs = std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count();
74 std::uint32_t eventType;
77 auto const ret = fi_eq_sread(
_raw, &eventType, &entry,
sizeof(entry), timeoutMs, 0);
106 fiCall(::fi_close,
"Failed to close event queue", &
_raw->fid);
113 if (ret == -FI_EAGAIN)
119 if (ret == -FI_EAVAIL)
121 ::fi_eq_err_entry eq_err{};
122 fi_eq_readerr(
_raw, &eq_err, 0);
136 case FI_SHUTDOWN:
return Event::fromRawCMEntry(*
reinterpret_cast<fi_eq_cm_entry const*
>(&entry), eventType);
break;
141 default:
MXL_WARN(
"Unhandled event on event queue: code: {}", eventType);
return std::nullopt;
std::optional< Event > handleReadResult(ssize_t, std::uint32_t, ::fi_eq_entry const &)
Handle the result of a blocking or non-blocking read.
void close()
Releases all underlying resources. This is called from the destructor and the move-assignment operato...
std::shared_ptr< Fabric > _fabric
std::optional< Event > readBlocking(std::chrono::steady_clock::duration timeout)
Perform a blocking read on the event queue.
::fid_eq * raw() noexcept
Returns a raw handle to the event queue.
EventQueue(EventQueue const &)=delete
static std::shared_ptr< EventQueue > open(std::shared_ptr< Fabric >, Attributes const &attr=Attributes::defaults())
Create a new event queue associated with the specified fabric.
std::optional< Event > read()
Perform a non-blocking read on the event queue. If no event is available in the queue,...
static Event fromRawCMEntry(::fi_eq_cm_entry const &raw, std::uint32_t eventType)
create an Event from a libfabric Connection Management event
static Event fromRawEntry(::fi_eq_entry const &raw, std::uint32_t eventType)
static Event fromError(std::shared_ptr< EventQueue > queue, ::fi_eq_err_entry const *raw)
create an Event from a libfabric event error entry
static FabricException make(int fiErrno, fmt::format_string< T... > fmt, T &&... args)
Create a new exception object.
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.
Attributes to configure newly created event queues.
static Attributes defaults()
Creates a configuration with all values set to reasonable defaults.
::fi_eq_attr raw() const noexcept
Returns the raw libfabric version of this object.