From e4fb604bc11d037902276d1dc773e4cae09da180 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 4 Aug 2021 08:31:56 -0700 Subject: [PATCH] Use pipe instead of pipe2 for compatibility with Mac OS --- src/google/protobuf/io/zero_copy_stream_unittest.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/io/zero_copy_stream_unittest.cc b/src/google/protobuf/io/zero_copy_stream_unittest.cc index 822115e023..fe9b6a191e 100644 --- a/src/google/protobuf/io/zero_copy_stream_unittest.cc +++ b/src/google/protobuf/io/zero_copy_stream_unittest.cc @@ -772,7 +772,12 @@ TEST_F(IoTest, NonBlockingFileIo) { for (int i = 0; i < kBlockSizeCount; i++) { for (int j = 0; j < kBlockSizeCount; j++) { int fd[2]; - ASSERT_EQ(pipe2(fd, O_NONBLOCK), 0); + // On Linux we could use pipe2 to make the pipe non-blocking in one step, + // but we instead use pipe and fcntl because pipe2 is not available on + // Mac OS. + ASSERT_EQ(pipe(fd), 0); + ASSERT_EQ(fcntl(fd[0], F_SETFL, O_NONBLOCK), 0); + ASSERT_EQ(fcntl(fd[1], F_SETFL, O_NONBLOCK), 0); std::mutex go_write; go_write.lock();