mirror of https://github.com/AxioDL/kabufuda.git
Add AsyncIONX.cpp
This commit is contained in:
parent
6f5cb6f972
commit
b585305009
|
@ -49,6 +49,10 @@ if(WIN32)
|
||||||
include/kabufuda/winsupport.hpp
|
include/kabufuda/winsupport.hpp
|
||||||
lib/kabufuda/AsyncIOWin32.cpp
|
lib/kabufuda/AsyncIOWin32.cpp
|
||||||
)
|
)
|
||||||
|
elseif(NX)
|
||||||
|
target_sources(kabufuda PRIVATE
|
||||||
|
lib/kabufuda/AsyncIONX.cpp
|
||||||
|
)
|
||||||
else()
|
else()
|
||||||
target_sources(kabufuda PRIVATE
|
target_sources(kabufuda PRIVATE
|
||||||
lib/kabufuda/AsyncIOPosix.cpp
|
lib/kabufuda/AsyncIOPosix.cpp
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
#ifdef __SWITCH__
|
||||||
|
#include <sys/types.h>
|
||||||
|
using SizeReturn = ssize_t;
|
||||||
|
#else
|
||||||
#include <aio.h>
|
#include <aio.h>
|
||||||
using SizeReturn = ssize_t;
|
using SizeReturn = ssize_t;
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
using SizeReturn = DWORD;
|
using SizeReturn = DWORD;
|
||||||
|
@ -16,7 +21,9 @@ using SizeReturn = DWORD;
|
||||||
namespace kabufuda {
|
namespace kabufuda {
|
||||||
|
|
||||||
class AsyncIO {
|
class AsyncIO {
|
||||||
#ifndef _WIN32
|
#ifdef __SWITCH__
|
||||||
|
FILE* m_fd;
|
||||||
|
#elif !defined(_WIN32)
|
||||||
int m_fd = -1;
|
int m_fd = -1;
|
||||||
std::vector<std::pair<struct aiocb, SizeReturn>> m_queue;
|
std::vector<std::pair<struct aiocb, SizeReturn>> m_queue;
|
||||||
#else
|
#else
|
||||||
|
@ -34,13 +41,19 @@ public:
|
||||||
AsyncIO& operator=(AsyncIO&& other);
|
AsyncIO& operator=(AsyncIO&& other);
|
||||||
AsyncIO(const AsyncIO* other) = delete;
|
AsyncIO(const AsyncIO* other) = delete;
|
||||||
AsyncIO& operator=(const AsyncIO& other) = delete;
|
AsyncIO& operator=(const AsyncIO& other) = delete;
|
||||||
void resizeQueue(size_t queueSz) { m_queue.resize(queueSz); }
|
void resizeQueue(size_t queueSz) {
|
||||||
|
#ifndef __SWITCH__
|
||||||
|
m_queue.resize(queueSz);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
bool asyncRead(size_t qIdx, void* buf, size_t length, off_t offset);
|
bool asyncRead(size_t qIdx, void* buf, size_t length, off_t offset);
|
||||||
bool asyncWrite(size_t qIdx, const void* buf, size_t length, off_t offset);
|
bool asyncWrite(size_t qIdx, const void* buf, size_t length, off_t offset);
|
||||||
ECardResult pollStatus(size_t qIdx, SizeReturn* szRet = nullptr) const;
|
ECardResult pollStatus(size_t qIdx, SizeReturn* szRet = nullptr) const;
|
||||||
ECardResult pollStatus() const;
|
ECardResult pollStatus() const;
|
||||||
void waitForCompletion() const;
|
void waitForCompletion() const;
|
||||||
#ifndef _WIN32
|
#ifdef __SWITCH__
|
||||||
|
explicit operator bool() const { return m_fd != nullptr; }
|
||||||
|
#elif !defined(_WIN32)
|
||||||
explicit operator bool() const { return m_fd != -1; }
|
explicit operator bool() const { return m_fd != -1; }
|
||||||
#else
|
#else
|
||||||
explicit operator bool() const { return m_fh != INVALID_HANDLE_VALUE; }
|
explicit operator bool() const { return m_fh != INVALID_HANDLE_VALUE; }
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
#include "kabufuda/AsyncIO.hpp"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace kabufuda {
|
||||||
|
|
||||||
|
AsyncIO::AsyncIO(SystemStringView filename, bool truncate) { m_fd = fopen(filename.data(), truncate ? "rw" : "ra"); }
|
||||||
|
|
||||||
|
AsyncIO::~AsyncIO() {
|
||||||
|
if (*this) {
|
||||||
|
fclose(m_fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncIO::AsyncIO(AsyncIO&& other) {
|
||||||
|
m_fd = other.m_fd;
|
||||||
|
other.m_fd = nullptr;
|
||||||
|
m_maxBlock = other.m_maxBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncIO& AsyncIO::operator=(AsyncIO&& other) {
|
||||||
|
if (*this) {
|
||||||
|
fclose(m_fd);
|
||||||
|
}
|
||||||
|
m_fd = other.m_fd;
|
||||||
|
other.m_fd = nullptr;
|
||||||
|
m_maxBlock = other.m_maxBlock;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AsyncIO::_waitForOperation(size_t qIdx) const {}
|
||||||
|
|
||||||
|
bool AsyncIO::asyncRead(size_t qIdx, void* buf, size_t length, off_t offset) {
|
||||||
|
return fread(buf, length, offset, m_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AsyncIO::asyncWrite(size_t qIdx, const void* buf, size_t length, off_t offset) {
|
||||||
|
return fwrite(buf, length, offset, m_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
ECardResult AsyncIO::pollStatus(size_t qIdx, SizeReturn* szRet) const { return ECardResult::READY; }
|
||||||
|
|
||||||
|
ECardResult AsyncIO::pollStatus() const { return ECardResult::READY; }
|
||||||
|
|
||||||
|
void AsyncIO::waitForCompletion() const {}
|
||||||
|
|
||||||
|
} // namespace kabufuda
|
Loading…
Reference in New Issue