aboutsummaryrefslogtreecommitdiff
path: root/src/common/platform/unix/UnixPipe.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-02-12 15:47:31 +0800
committercrupest <crupest@outlook.com>2024-02-14 22:58:11 +0800
commitf9c404510584faab71b9e9d911d9b396b0f420b0 (patch)
treea46280ef09459e1f2997ad4a15f2d4053519e634 /src/common/platform/unix/UnixPipe.cpp
parent96ed44c31b92f1492be68c084e8b18972d549743 (diff)
downloadcru-f9c404510584faab71b9e9d911d9b396b0f420b0.tar.gz
cru-f9c404510584faab71b9e9d911d9b396b0f420b0.tar.bz2
cru-f9c404510584faab71b9e9d911d9b396b0f420b0.zip
WORKING: add non-block flag for unix pipe.
Diffstat (limited to 'src/common/platform/unix/UnixPipe.cpp')
-rw-r--r--src/common/platform/unix/UnixPipe.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/common/platform/unix/UnixPipe.cpp b/src/common/platform/unix/UnixPipe.cpp
index 8393f022..4d081d5e 100644
--- a/src/common/platform/unix/UnixPipe.cpp
+++ b/src/common/platform/unix/UnixPipe.cpp
@@ -2,14 +2,23 @@
#include "cru/common/Exception.h"
#include "cru/common/log/Logger.h"
+#include <fcntl.h>
+#include <sys/fcntl.h>
#include <unistd.h>
namespace cru::platform::unix {
-UnixPipe::UnixPipe(Usage usage) : usage_(usage) {
+UnixPipe::UnixPipe(Usage usage, UnixPipeFlag flags)
+ : usage_(usage), flags_(flags) {
int fds[2];
if (pipe(fds) != 0) {
throw ErrnoException(u"Failed to create unix pipe.");
}
+
+ if (flags & UnixPipeFlags::NonBlock) {
+ fcntl(fds[0], F_SETFL, O_NONBLOCK);
+ fcntl(fds[1], F_SETFL, O_NONBLOCK);
+ }
+
read_fd_ = fds[0];
write_fd_ = fds[1];
}