Commit 9056dcaf authored by Max Kellermann's avatar Max Kellermann

system/FileDescriptor: add method CreatePipeNonBlock()

parent 2119e4fd
......@@ -125,6 +125,33 @@ FileDescriptor::CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept
#ifndef _WIN32
bool
FileDescriptor::CreatePipeNonBlock(FileDescriptor &r,
FileDescriptor &w) noexcept
{
int fds[2];
#ifdef HAVE_PIPE2
const int flags = O_CLOEXEC|O_NONBLOCK;
const int result = pipe2(fds, flags);
#else
const int result = pipe(fds);
#endif
if (result < 0)
return false;
r = FileDescriptor(fds[0]);
w = FileDescriptor(fds[1]);
#ifndef HAVE_PIPE2
r.SetNonBlocking();
w.SetNonBlocking();
#endif
return true;
}
void
FileDescriptor::SetNonBlocking() noexcept
{
......
......@@ -115,6 +115,9 @@ public:
static bool CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept;
#ifndef _WIN32
static bool CreatePipeNonBlock(FileDescriptor &r,
FileDescriptor &w) noexcept;
/**
* Enable non-blocking mode on this file descriptor.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment