1#ifndef SDL3PP_ASYNCIO_H_
2#define SDL3PP_ASYNCIO_H_
4#include <SDL3/SDL_asyncio.h>
6#include "SDL3pp_stdinc.h"
352 void Write(
void* ptr,
367 SDL_ASYNCIO_TASK_READ;
370 SDL_ASYNCIO_TASK_WRITE;
373 SDL_ASYNCIO_TASK_CLOSE;
383 SDL_ASYNCIO_COMPLETE;
389 SDL_ASYNCIO_CANCELED;
526 std::optional<AsyncIOOutcome>
GetResult();
672 return AsyncIO(std::move(file), std::move(mode));
676 :
AsyncIO(SDL_AsyncIOFromFile(file, mode))
696 return CheckError(SDL_GetAsyncIOSize(asyncio));
743 CheckError(SDL_ReadAsyncIO(asyncio, ptr, offset, size, queue, userdata));
796 CheckError(SDL_WriteAsyncIO(asyncio, ptr, offset, size, queue, userdata));
859 return SDL_CloseAsyncIO(asyncio, flush, queue, userdata);
920 SDL_DestroyAsyncIOQueue(queue);
950 if (
AsyncIOOutcome outcome; SDL_GetAsyncIOResult(queue, &outcome)) {
1004 SDL_WaitAsyncIOResult(queue, &outcome,
narrowS32(timeout.count()))) {
1007 return std::nullopt;
1050 if (
AsyncIOOutcome outcome; SDL_WaitAsyncIOResult(queue, &outcome, -1)) {
1053 return std::nullopt;
1091 SDL_SignalAsyncIOQueue(queue);
1131 CheckError(SDL_LoadFileAsync(file, queue, userdata));
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:53
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:56
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Sint64 GetSize()
Use this function to get the size of the data stream in an AsyncIO.
Definition SDL3pp_asyncio.h:699
ResourceRef< AsyncIO > AsyncIORef
Reference for AsyncIO.
Definition SDL3pp_asyncio.h:100
void Write(void *ptr, Uint64 offset, Uint64 size, AsyncIOQueueRef queue, void *userdata)
Start an async write.
Definition SDL3pp_asyncio.h:799
void Destroy()
Destroy a previously-created async I/O task queue.
Definition SDL3pp_asyncio.h:923
void SignalAsyncIOQueue(AsyncIOQueueRef queue)
Wake up any threads that are blocking in AsyncIOQueue.WaitResult().
Definition SDL3pp_asyncio.h:1089
void ReadAsyncIO(AsyncIORef asyncio, void *ptr, Uint64 offset, Uint64 size, AsyncIOQueueRef queue, void *userdata)
Start an async read.
Definition SDL3pp_asyncio.h:736
constexpr AsyncIOResult ASYNCIO_CANCELED
request was canceled before completing.
Definition SDL3pp_asyncio.h:388
AsyncIOQueue CreateAsyncIOQueue()
Create a task queue for tracking multiple I/O operations.
Definition SDL3pp_asyncio.h:884
SDL_AsyncIOOutcome AsyncIOOutcome
Information about a completed asynchronous I/O request.
Definition SDL3pp_asyncio.h:396
constexpr AsyncIOTaskType ASYNCIO_TASK_CLOSE
A close operation.
Definition SDL3pp_asyncio.h:372
std::optional< AsyncIOOutcome > WaitAsyncIOResult(AsyncIOQueueRef queue, Milliseconds timeout)
Block until an async I/O task queue has a completed task.
Definition SDL3pp_asyncio.h:1000
AsyncIO AsyncIOFromFile(StringParam file, StringParam mode)
Use this function to create a new AsyncIO object for reading from and/or writing to a named file.
Definition SDL3pp_asyncio.h:670
constexpr AsyncIOTaskType ASYNCIO_TASK_READ
A read operation.
Definition SDL3pp_asyncio.h:366
SDL_AsyncIOResult AsyncIOResult
Possible outcomes of an asynchronous I/O task.
Definition SDL3pp_asyncio.h:380
void Signal()
Wake up any threads that are blocking in AsyncIOQueue.WaitResult().
Definition SDL3pp_asyncio.h:1094
std::optional< AsyncIOOutcome > GetResult()
Query an async I/O task queue for completed tasks.
Definition SDL3pp_asyncio.h:956
constexpr AsyncIOResult ASYNCIO_COMPLETE
request was completed without error
Definition SDL3pp_asyncio.h:382
bool Close(bool flush, AsyncIOQueueRef queue, void *userdata)
Close and free any allocated resources for an async I/O object.
Definition SDL3pp_asyncio.h:862
std::optional< AsyncIOOutcome > WaitResult()
Block until an async I/O task queue has a completed task.
Definition SDL3pp_asyncio.h:1062
constexpr AsyncIOResult ASYNCIO_FAILURE
request failed for some reason; check GetError()!
Definition SDL3pp_asyncio.h:385
void Read(void *ptr, Uint64 offset, Uint64 size, AsyncIOQueueRef queue, void *userdata)
Start an async read.
Definition SDL3pp_asyncio.h:746
SDL_AsyncIOQueue * AsyncIOQueueRaw
Alias to raw representation for AsyncIOQueue.
Definition SDL3pp_asyncio.h:106
SDL_AsyncIOTaskType AsyncIOTaskType
Types of asynchronous I/O tasks.
Definition SDL3pp_asyncio.h:364
void DestroyAsyncIOQueue(AsyncIOQueueRaw queue)
Destroy a previously-created async I/O task queue.
Definition SDL3pp_asyncio.h:918
Sint64 GetAsyncIOSize(AsyncIORef asyncio)
Use this function to get the size of the data stream in an AsyncIO.
Definition SDL3pp_asyncio.h:694
void WriteAsyncIO(AsyncIORef asyncio, void *ptr, Uint64 offset, Uint64 size, AsyncIOQueueRef queue, void *userdata)
Start an async write.
Definition SDL3pp_asyncio.h:789
SDL_AsyncIO * AsyncIORaw
Alias to raw representation for AsyncIO.
Definition SDL3pp_asyncio.h:93
void LoadFileAsync(StringParam file, AsyncIOQueueRef queue, void *userdata)
Load all the data from a file path, asynchronously.
Definition SDL3pp_asyncio.h:1127
bool CloseAsyncIO(AsyncIORaw asyncio, bool flush, AsyncIOQueueRef queue, void *userdata)
Close and free any allocated resources for an async I/O object.
Definition SDL3pp_asyncio.h:854
constexpr AsyncIOTaskType ASYNCIO_TASK_WRITE
A write operation.
Definition SDL3pp_asyncio.h:369
ResourceRef< AsyncIOQueue > AsyncIOQueueRef
Reference for AsyncIOQueue.
Definition SDL3pp_asyncio.h:113
std::optional< AsyncIOOutcome > GetAsyncIOResult(AsyncIOQueueRef queue)
Query an async I/O task queue for completed tasks.
Definition SDL3pp_asyncio.h:948
AsyncIOQueue()
Create a task queue for tracking multiple I/O operations.
Definition SDL3pp_asyncio.h:886
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
constexpr LogCategory LOG_CATEGORY_ERROR
ERROR.
Definition SDL3pp_log.h:435
::Sint64 Sint64
A signed 64-bit integer type.
Definition SDL3pp_stdinc.h:305
std::chrono::milliseconds Milliseconds
Duration in Miliseconds (Uint32).
Definition SDL3pp_stdinc.h:335
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:320
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6257
A queue of completed asynchronous I/O tasks.
Definition SDL3pp_asyncio.h:417
~AsyncIOQueue()
Destructor.
Definition SDL3pp_asyncio.h:465
constexpr AsyncIOQueue(AsyncIOQueue &&other) noexcept
Move constructor.
Definition SDL3pp_asyncio.h:436
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
constexpr AsyncIOQueue & operator=(AsyncIOQueue &&other) noexcept
Assignment operator.
Definition SDL3pp_asyncio.h:468
AsyncIOQueue & operator=(const AsyncIOQueue &other)=delete
Assignment operator.
constexpr AsyncIOQueue(const AsyncIOQueue &other)=delete
Copy constructor.
constexpr AsyncIOQueue(AsyncIOQueueRaw resource) noexcept
Constructs from raw AsyncIOQueue.
Definition SDL3pp_asyncio.h:427
The asynchronous I/O operation structure.
Definition SDL3pp_asyncio.h:128
constexpr AsyncIO(const AsyncIO &other)=delete
Copy constructor.
constexpr AsyncIO(AsyncIORaw resource) noexcept
Constructs from raw AsyncIO.
Definition SDL3pp_asyncio.h:138
constexpr AsyncIO & operator=(AsyncIO &&other) noexcept
Assignment operator.
Definition SDL3pp_asyncio.h:207
~AsyncIO()
Destructor.
Definition SDL3pp_asyncio.h:198
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
AsyncIO & operator=(const AsyncIO &other)=delete
Assignment operator.
constexpr AsyncIO(AsyncIO &&other) noexcept
Move constructor.
Definition SDL3pp_asyncio.h:147
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:156