/*** 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 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 &pin); void LIOS_Reset(); bool HasState(); void SetMemory(const AuSPtr &view); void SetMemory(const AuSPtr &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 {}; private: AuUInt64 dataPtr_ {}; AuUInt dataLen_ {}; AuSPtr pin_; AuSPtr 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 &handles, const AuList &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(); }