aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-09-04 22:59:47 +0800
committerYuqian Yang <crupest@crupest.life>2025-09-04 22:59:47 +0800
commit4c3098be1c5abaed610b8f10216d59829fc107ce (patch)
tree2f1367f1e6ed35ad831bba5888a6dfdbfa72a91b
parentfdddc7f4a8884a8481dc71c0f34b8775659ba236 (diff)
downloadcru-4c3098be1c5abaed610b8f10216d59829fc107ce.tar.gz
cru-4c3098be1c5abaed610b8f10216d59829fc107ce.tar.bz2
cru-4c3098be1c5abaed610b8f10216d59829fc107ce.zip
Fix SetFileDescriptorFlags (by adding testing).
-rw-r--r--src/base/platform/unix/UnixFile.cpp2
-rw-r--r--test/base/platform/unix/UnixFileTest.cpp14
2 files changed, 13 insertions, 3 deletions
diff --git a/src/base/platform/unix/UnixFile.cpp b/src/base/platform/unix/UnixFile.cpp
index 763161ce..6d2dea89 100644
--- a/src/base/platform/unix/UnixFile.cpp
+++ b/src/base/platform/unix/UnixFile.cpp
@@ -98,7 +98,7 @@ ssize_t UnixFileDescriptor::Read(void* buffer, size_t size) {
void UnixFileDescriptor::SetFileDescriptorFlags(int flags) {
EnsureValid();
- if (::fcntl(GetValue(), F_SETFL, flags) != -1) {
+ if (::fcntl(GetValue(), F_SETFL, flags) == -1) {
throw ErrnoException("Failed to set flags on file descriptor.");
}
}
diff --git a/test/base/platform/unix/UnixFileTest.cpp b/test/base/platform/unix/UnixFileTest.cpp
index d5bba0db..b18b6bce 100644
--- a/test/base/platform/unix/UnixFileTest.cpp
+++ b/test/base/platform/unix/UnixFileTest.cpp
@@ -1,12 +1,12 @@
-#include "cru/base/platform/unix/UnixFileStream.h"
+#include "cru/base/platform/unix/UnixFile.h"
#include <catch2/catch_test_macros.hpp>
#include <fcntl.h>
#include <filesystem>
-TEST_CASE("UnixFile Work", "[unix]") {
+TEST_CASE("UnixFile Auto Close", "[unix]") {
using namespace cru;
using namespace cru::platform::unix;
@@ -36,3 +36,13 @@ TEST_CASE("UnixFile Work", "[unix]") {
std::filesystem::remove(temp_file_path);
}
+
+TEST_CASE("UnixFile NonBlock Read", "[unix]") {
+ using namespace cru;
+ using namespace cru::platform::unix;
+
+ char buffer[1];
+
+ auto pipe = OpenUniDirectionalPipe(UnixPipeFlags::NonBlock);
+ REQUIRE(pipe.read.Read(buffer, 1) == -1);
+}