[+] AuIPC::NewPipeEx(AuUInt32 uPipeLength)

This commit is contained in:
Reece Wilson 2023-10-20 10:45:59 +01:00
parent 718b5a9316
commit 871479172b
3 changed files with 48 additions and 12 deletions

View File

@ -67,6 +67,13 @@ namespace Aurora::IO::IPC
*/
AUKN_SYM AuSPtr<IPCPipe> NewPipe();
/**
* @brief
* @param uBytesLength
* @return
*/
AUKN_SYM AuSPtr<IPCPipe> NewPipeEx(AuUInt32 uBytesLength);
/**
* @brief
* @param handleString

View File

@ -335,7 +335,7 @@ namespace Aurora::IO::IPC
AuString {};
}
AUKN_SYM AuSPtr<IPCPipe> NewPipe()
AUKN_SYM AuSPtr<IPCPipe> NewPipeEx(AuUInt32 uBytesLength)
{
IPC::IPCHandle handle;
IPC::IPCToken token;
@ -346,15 +346,16 @@ namespace Aurora::IO::IPC
auto path = token.ToNTPath();
auto name = "\\\\.\\pipe\\" + token.ToNTPath();
auto maxLength = 16 * AuHwInfo::GetPageSize() ? AuHwInfo::GetPageSize() : 4096;
auto pageSize = AuHwInfo::GetPageSize();
auto maxLength = uBytesLength ? AuPageRound(uBytesLength, pageSize) : pageSize ? 16 * pageSize : 4096;
auto pipeServer = CreateNamedPipeA(name.c_str(),
PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_OVERLAPPED,
PIPE_WAIT,
1,
maxLength,
maxLength,
NMPWAIT_WAIT_FOREVER,
nullptr);
PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_OVERLAPPED,
PIPE_WAIT,
1,
maxLength,
maxLength,
NMPWAIT_WAIT_FOREVER,
nullptr);
if ((!pipeServer) ||
(pipeServer == INVALID_HANDLE_VALUE))
{
@ -373,6 +374,11 @@ namespace Aurora::IO::IPC
return object;
}
AUKN_SYM AuSPtr<IPCPipe> NewPipe()
{
return NewPipeEx(0);
}
AUKN_SYM AuSPtr<IPCPipe> ImportPipe(const AuString &handleString)
{
IPCHandle handle;

View File

@ -364,7 +364,7 @@ namespace Aurora::IO::IPC
return handle.ToString();
}
AUKN_SYM AuSPtr<IPCPipe> NewPipe()
AUKN_SYM AuSPtr<IPCPipe> NewPipeEx(AuUInt32 uPipeLength)
{
IPCToken readEnd, writeEnd;
int fds1[2];
@ -386,18 +386,36 @@ namespace Aurora::IO::IPC
if (::pipe(fds1) == -1)
{
SysPushErrorIO();
SysPushErrorIO("no pipe");
return {};
}
if (::pipe(fds2) == -1)
{
SysPushErrorIO();
SysPushErrorIO("no pipe");
::close(fds1[0]);
::close(fds1[1]);
return {};
}
#if defined(F_SETPIPE_SZ)
if (uPipeLength)
{
uPipeLength = AuPageRound(uPipeLength, AuHwInfo::GetPageSize());
if (fcntl(fds1[1], F_SETPIPE_SZ, uPipeLength) == -1 ||
fcntl(fds2[1], F_SETPIPE_SZ, uPipeLength) == -1)
{
SysPushErrorIO("couldnt expand pipe");
::close(fds1[0]);
::close(fds1[1]);
::close(fds2[0]);
::close(fds2[1]);
return {};
}
}
#endif
if (!IO::UNIX::FDServe(fds1[0], readEnd))
{
SysPushErrorIO();
@ -438,6 +456,11 @@ namespace Aurora::IO::IPC
return handle;
}
AUKN_SYM AuSPtr<IPCPipe> NewPipe()
{
return NewPipeEx(0);
}
AUKN_SYM AuSPtr<IPCPipe> ImportPipe(const AuString &handleString)
{
int fds[2] {-1, -1};