AuroraRuntime/Source/IO/UNIX/UnixIO.cpp

66 lines
1.3 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: UnixIO.cpp
Date: 2022-4-12
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "UnixIO.hpp"
#include "FDIpcServer.hpp"
namespace Aurora::IO::UNIX
{
AUKN_SYM AuString ShareFileDescriptor(int fd)
{
IPC::IPCHandle handle;
if (!FDServe(false, false, false, false, fd, handle))
{
return {};
}
return handle.ToString();
}
AUKN_SYM void ShareFileDescriptorStop(const AuString &handle)
{
IPC::IPCHandle handle2;
if (!handle2.FromString(handle))
{
SysPushErrorIO("Invalid handle string");
return;
}
FDServeEnd(handle2);
}
AUKN_SYM int ShareFileDescriptorAccept(const AuString &handle)
{
IPC::IPCHandle handle2;
if (!handle2.FromString(handle))
{
SysPushErrorIO("Invalid handle string");
return -1;
}
int fd {-1};
if (!FDAccept(handle2, fd))
{
SysPushErrorNested();
return -1;
}
return fd;
}
void InitUnixIO()
{
InitIPCBackend();
}
void DeinitUnixIO()
{
DeinitIPCBackend();
}
}