vrtd::Buffer

class Buffer

RAII wrapper for a vrtd buffer allocation.

A Buffer owns the underlying vrtd_buffer, including its qpair FD and host-side staging buffer. Destruction closes the FD and releases the mapping.

Note

Move-only; copying is disabled. The moved-from object is closed.

Public Functions

uint32_t getDeviceNum() const noexcept

Device index owning this buffer.

BufferAllocType getAllocType() const noexcept

Allocation type requested for this buffer.

BufferAllocDir getAllocDir() const noexcept

QDMA transfer direction for this buffer.

uint64_t getAllocArg() const noexcept

Allocation argument (HBM region index for HBM allocations).

uint64_t getSize() const noexcept

Allocated size in bytes (rounded to subregions).

uint64_t getPhysAddr() const noexcept

Physical device address for this allocation.

void *data() const noexcept

Pointer to the host staging buffer.

void *data() noexcept

Pointer to the host staging buffer.

int getFd() const noexcept

Borrow the owned file descriptor without transferring ownership.

Warning

Do not close the returned FD directly unless you have called releaseFd(). Prefer close().

int releaseFd() noexcept

Release qpair FD ownership to the caller.

The buffer remains valid, but will no longer close the FD on destruction.

void close() noexcept

Close and destroy the buffer via vrtd (idempotent).

Releases the server-side allocation and local staging buffer. Errors are ignored to preserve noexcept semantics.

bool isClosed() const noexcept

Whether the buffer has been closed or destroyed.

void syncToDevice(uint64_t offset, uint64_t size)

Sync host buffer contents to the device.

Throws:

vrtd::Error – on error.

void syncFromDevice(uint64_t offset, uint64_t size)

Sync device contents into the host buffer.

Throws:

vrtd::Error – on error.

std::fstream fstream(std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out | std::ios_base::binary) const

Obtain a std::fstream bound to this buffer FD.

Note

Implementation is Linux-specific and relies on /proc/self/fd.

Parameters:

mode – Standard iostream open mode (defaults to in|out|binary).

Throws:

std::runtime_error – if the buffer is closed or the stream cannot be opened.

Returns:

A std::fstream owning its own FD.