AuroraRuntime/Source/IO/UNIX/IOSubmit.Linux.hpp

87 lines
2.8 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IOSubmit.Linux.hpp
Date: 2022-4-12
Author: Reece
Note: I want APCs, overlapped, and event based IO on Linux. Gib.
***/
#pragma once
#include <linux/aio_abi.h>
#include <poll.h>
namespace Aurora::IO::UNIX
{
struct ASubmittable
{
ASubmittable();
~ASubmittable();
virtual void LIOS_Process(AuUInt32 read, bool failure, int err, bool mark) = 0;
void LIOS_SendProcess(AuUInt32 read, bool failure, int err, bool mark = false);
void LIOS_Init(const AuSPtr<void> &pin);
void LIOS_Reset();
bool LIOS_Cancel();
bool HasState();
void LIOS_ProcessStack(AuUInt32 read, bool failure, int err, bool mark);
#if defined(__AUHAS_COROUTINES_CO_AWAIT) && defined(AU_LANG_CPP_20_)
AuVoidTask LIOS_ProcessStack_(AuUInt32 read, bool failure, int err, bool mark);
#endif
void SetMemory(const AuMemoryViewRead &view);
void SetMemory(const AuMemoryViewWrite &view);
AuUInt64 GetData();
AuUInt64 GetBuf();
AuUInt GetBufLength();
iocb & GetIOCB();
int GetOrCreateFdPollForBlockingRead(int fd);
// Hack for blocking reads
bool bIsReadPending {};
bool bIsWritePending {};
AuUInt64 offset2 {};
int fd2 {};
AuLoop::ILSEvent *optEvent2 {};
aio_context_t abortContext {};
// TODO:
AuSPtr<void> pin_;
AuSPtr<void> memPin_;
AuMemoryViewRead readView;
AuMemoryViewWrite writeView;
private:
AuUInt64 dataPtr_ {};
AuUInt dataLen_ {};
int tempEPoll {-1};
iocb cb {};
};
// Yield/Wait shims
bool LinuxOverlappedWaitForOne (AuUInt32 timeout, AuUInt read, AuUInt write, bool &bReadTriggered, bool &bWriteTriggered);
bool LinuxOverlappedWaitForAtleastOne(AuUInt32 timeout, const AuList<AuUInt> &handles, const AuList<AuUInt> &handlesWrite, AuUInt &one, AuUInt &two);
bool LinuxOverlappedPoll (AuUInt32 timeout);
int LinuxOverlappedEpollShim(int epfd, struct epoll_event *events,
int maxevents, int timeout);
// TODO:
//int LinuxOverlappedPosixPoll(struct pollfd *pPollFDs, nfds_t uCount, int timeout);
bool LinuxOverlappedYield(bool bUserspaceOnly = false);
// Work queue
bool LinuxOverlappedSubmitRead (int fd, AuUInt offset, ASubmittable *context, AuLoop::ILSEvent *optEvent, bool bWaitForRead = false /* use on unsupported blocking interfaces. costs an epoll to work around >current< limitiations in io_submit*/);
bool LinuxOverlappedSubmitWrite(int fd, AuUInt offset, ASubmittable *context, AuLoop::ILSEvent *optEvent);
// TODO: Stream copy operations
// Bookkeeping
bool SendIOBuffers();
}