[libc-commits] [libc] [libc] Implement shutdown on linux (PR #192933)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Mon Apr 20 06:52:14 PDT 2026
================
@@ -0,0 +1,77 @@
+//===-- Unittests for shutdown --------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "hdr/sys_socket_macros.h"
+#include "hdr/types/ssize_t.h"
+#include "src/sys/socket/shutdown.h"
+#include "src/sys/socket/socketpair.h"
+#include "src/unistd/close.h"
+#include "src/unistd/read.h"
+
+#include "test/UnitTest/ErrnoCheckingTest.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
+using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+using LlvmLibcShutdownTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcShutdownTest, ShutWrProducesEOF) {
+ int sv[2];
+ ASSERT_THAT(LIBC_NAMESPACE::socketpair(AF_UNIX, SOCK_STREAM, 0, sv),
+ Succeeds(0));
+
+ // Shut down write on sv[0].
+ ASSERT_THAT(LIBC_NAMESPACE::shutdown(sv[0], SHUT_WR), Succeeds(0));
+
+ // Reading from sv[1] should return 0 (EOF).
+ char read_buf[10];
+ ASSERT_EQ(LIBC_NAMESPACE::read(sv[1], read_buf, sizeof(read_buf)),
----------------
michaelrj-google wrote:
nit: if this is specifically returning `EOF` the assert should compare against that and not `ssize_t(0)`.
https://github.com/llvm/llvm-project/pull/192933
More information about the libc-commits
mailing list