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

75 lines
2.3 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>
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 SetMemory(const AuSPtr<AuMemoryViewRead> &view);
void SetMemory(const AuSPtr<AuMemoryViewWrite> &view);
AuUInt64 GetData();
AuUInt64 GetBuf();
AuUInt GetBufLength();
iocb & GetIOCB();
int GetOrCreateFdPollForBlockingRead(int fd);
// Hack for blocking reads
bool bIsReadPending {};
AuUInt64 offset2 {};
int fd2 {};
AuLoop::ILSEvent *optEvent2 {};
aio_context_t abortContext {};
private:
AuUInt64 dataPtr_ {};
AuUInt dataLen_ {};
AuSPtr<void> pin_;
AuSPtr<void> memPin_;
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);
bool LinuxOverlappedYield();
// 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();
}