1#ifndef SDL3PP_ASYNCIO_H_
2#define SDL3PP_ASYNCIO_H_
4#include <SDL3/SDL_asyncio.h>
6#include "SDL3pp_stdinc.h"
265 void Write(
void* ptr,
286 using AsyncIOBase::AsyncIOBase;
372 SDL_ASYNCIO_TASK_READ;
375 SDL_ASYNCIO_TASK_WRITE;
378 SDL_ASYNCIO_TASK_CLOSE;
388 SDL_ASYNCIO_COMPLETE;
394 SDL_ASYNCIO_CANCELED;
461 std::optional<AsyncIOOutcome>
GetResult();
587 using AsyncIOQueueBase::AsyncIOQueueBase;
677 return AsyncIO(std::move(file), std::move(mode));
681 :
AsyncIO(SDL_AsyncIOFromFile(file, mode))
701 return CheckError(SDL_GetAsyncIOSize(asyncio));
748 CheckError(SDL_ReadAsyncIO(asyncio, ptr, offset, size, queue, userdata));
801 CheckError(SDL_WriteAsyncIO(asyncio, ptr, offset, size, queue, userdata));
864 return SDL_CloseAsyncIO(asyncio, flush, queue, userdata);
926 SDL_DestroyAsyncIOQueue(queue);
956 if (
AsyncIOOutcome outcome; SDL_GetAsyncIOResult(queue, &outcome)) {
1010 SDL_WaitAsyncIOResult(queue, &outcome,
narrowS32(timeout.count()))) {
1013 return std::nullopt;
1056 if (
AsyncIOOutcome outcome; SDL_WaitAsyncIOResult(queue, &outcome, -1)) {
1059 return std::nullopt;
1097 SDL_SignalAsyncIOQueue(queue);
1137 CheckError(SDL_LoadFileAsync(file, queue, userdata));
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
ResourceRefT< AsyncIOQueueBase > AsyncIOQueueRef
Reference for AsyncIOQueue.
Definition SDL3pp_asyncio.h:118
Sint64 GetSize()
Use this function to get the size of the data stream in an AsyncIO.
Definition SDL3pp_asyncio.h:704
void SignalAsyncIOQueue(AsyncIOQueueRef queue)
Wake up any threads that are blocking in WaitAsyncIOResult().
Definition SDL3pp_asyncio.h:1095
void ReadAsyncIO(AsyncIORef asyncio, void *ptr, Uint64 offset, Uint64 size, AsyncIOQueueRef queue, void *userdata)
Start an async read.
Definition SDL3pp_asyncio.h:741
constexpr AsyncIOResult ASYNCIO_CANCELED
request was canceled before completing.
Definition SDL3pp_asyncio.h:393
AsyncIOQueue CreateAsyncIOQueue()
Create a task queue for tracking multiple I/O operations.
Definition SDL3pp_asyncio.h:891
bool Close(bool flush, AsyncIOQueueRef queue, void *userdata)
Close and free any allocated resources for an async I/O object.
Definition SDL3pp_asyncio.h:867
ResourceRefT< AsyncIOBase > AsyncIORef
Reference for AsyncIO.
Definition SDL3pp_asyncio.h:102
SDL_AsyncIOOutcome AsyncIOOutcome
Information about a completed asynchronous I/O request.
Definition SDL3pp_asyncio.h:401
constexpr AsyncIOTaskType ASYNCIO_TASK_CLOSE
A close operation.
Definition SDL3pp_asyncio.h:377
std::optional< AsyncIOOutcome > WaitAsyncIOResult(AsyncIOQueueRef queue, Milliseconds timeout)
Block until an async I/O task queue has a completed task.
Definition SDL3pp_asyncio.h:1006
void Write(void *ptr, Uint64 offset, Uint64 size, AsyncIOQueueRef queue, void *userdata)
Start an async write.
Definition SDL3pp_asyncio.h:804
std::optional< AsyncIOOutcome > GetResult()
Query an async I/O task queue for completed tasks.
Definition SDL3pp_asyncio.h:962
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:675
constexpr AsyncIOTaskType ASYNCIO_TASK_READ
A read operation.
Definition SDL3pp_asyncio.h:371
void Read(void *ptr, Uint64 offset, Uint64 size, AsyncIOQueueRef queue, void *userdata)
Start an async read.
Definition SDL3pp_asyncio.h:751
SDL_AsyncIOResult AsyncIOResult
Possible outcomes of an asynchronous I/O task.
Definition SDL3pp_asyncio.h:385
constexpr AsyncIOResult ASYNCIO_COMPLETE
request was completed without error
Definition SDL3pp_asyncio.h:387
std::optional< AsyncIOOutcome > WaitResult()
Block until an async I/O task queue has a completed task.
Definition SDL3pp_asyncio.h:1068
constexpr AsyncIOResult ASYNCIO_FAILURE
request failed for some reason; check GetError()!
Definition SDL3pp_asyncio.h:390
SDL_AsyncIOQueue * AsyncIOQueueRaw
Alias to raw representation for AsyncIOQueue.
Definition SDL3pp_asyncio.h:111
SDL_AsyncIOTaskType AsyncIOTaskType
Types of asynchronous I/O tasks.
Definition SDL3pp_asyncio.h:369
void DestroyAsyncIOQueue(AsyncIOQueueRaw queue)
Destroy a previously-created async I/O task queue.
Definition SDL3pp_asyncio.h:924
Sint64 GetAsyncIOSize(AsyncIORef asyncio)
Use this function to get the size of the data stream in an AsyncIO.
Definition SDL3pp_asyncio.h:699
void WriteAsyncIO(AsyncIORef asyncio, void *ptr, Uint64 offset, Uint64 size, AsyncIOQueueRef queue, void *userdata)
Start an async write.
Definition SDL3pp_asyncio.h:794
SDL_AsyncIO * AsyncIORaw
Alias to raw representation for AsyncIO.
Definition SDL3pp_asyncio.h:95
void LoadFileAsync(StringParam file, AsyncIOQueueRef queue, void *userdata)
Load all the data from a file path, asynchronously.
Definition SDL3pp_asyncio.h:1133
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:859
void Signal()
Wake up any threads that are blocking in WaitAsyncIOResult().
Definition SDL3pp_asyncio.h:1100
constexpr AsyncIOTaskType ASYNCIO_TASK_WRITE
A write operation.
Definition SDL3pp_asyncio.h:374
void Destroy()
Destroy a previously-created async I/O task queue.
Definition SDL3pp_asyncio.h:929
std::optional< AsyncIOOutcome > GetAsyncIOResult(AsyncIOQueueRef queue)
Query an async I/O task queue for completed tasks.
Definition SDL3pp_asyncio.h:954
AsyncIOQueue()
Create a task queue for tracking multiple I/O operations.
Definition SDL3pp_asyncio.h:893
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:441
::Sint64 Sint64
A signed 64-bit integer type.
Definition SDL3pp_stdinc.h:311
std::chrono::milliseconds Milliseconds
Duration in Miliseconds (Uint32).
Definition SDL3pp_stdinc.h:341
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:326
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6263
Base class to AsyncIO.
Definition SDL3pp_asyncio.h:126
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Base class to AsyncIOQueue.
Definition SDL3pp_asyncio.h:409
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
A queue of completed asynchronous I/O tasks.
Definition SDL3pp_asyncio.h:586
~AsyncIOQueue()
Destructor.
Definition SDL3pp_asyncio.h:627
constexpr AsyncIOQueue(AsyncIOQueue &&other) noexcept
Move constructor.
Definition SDL3pp_asyncio.h:602
constexpr AsyncIOQueue & operator=(AsyncIOQueue &&other) noexcept
Assignment operator.
Definition SDL3pp_asyncio.h:630
constexpr AsyncIOQueue(AsyncIOQueueRaw resource) noexcept
Constructs from raw AsyncIOQueue.
Definition SDL3pp_asyncio.h:596
The asynchronous I/O operation structure.
Definition SDL3pp_asyncio.h:285
constexpr AsyncIO(AsyncIORaw resource) noexcept
Constructs from raw AsyncIO.
Definition SDL3pp_asyncio.h:295
constexpr AsyncIO & operator=(AsyncIO &&other) noexcept
Assignment operator.
Definition SDL3pp_asyncio.h:357
~AsyncIO()
Destructor.
Definition SDL3pp_asyncio.h:348
constexpr AsyncIO(AsyncIO &&other) noexcept
Move constructor.
Definition SDL3pp_asyncio.h:301
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93