git: 3bc122d27064 - main - tests/unix_seqpacket: test that data can be sent before accept(2)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 28 Feb 2024 22:33:10 UTC
The branch main has been updated by glebius:
URL: https://cgit.FreeBSD.org/src/commit/?id=3bc122d27064957911570c1037e6b644b7303c17
commit 3bc122d27064957911570c1037e6b644b7303c17
Author: Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2024-02-28 22:32:46 +0000
Commit: Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2024-02-28 22:32:46 +0000
tests/unix_seqpacket: test that data can be sent before accept(2)
This is undocumented feature of PF_UNIX/SOCK_STREAM and thus of
PF_UNIX/SOCK_SEQPACKET, too. Put the test into this file, since this file
is most advanced and has all primitives to write this test in minimum
number of lines.
Differential Revision: https://reviews.freebsd.org/D43853
---
tests/sys/kern/unix_seqpacket_test.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/tests/sys/kern/unix_seqpacket_test.c b/tests/sys/kern/unix_seqpacket_test.c
index 3ea7bb3ea165..cde427401970 100644
--- a/tests/sys/kern/unix_seqpacket_test.c
+++ b/tests/sys/kern/unix_seqpacket_test.c
@@ -501,6 +501,32 @@ ATF_TC_BODY(connect, tc)
close(s2);
}
+/*
+ * An undocumented feature that we probably want to preserve: sending to
+ * a socket that isn't yet accepted lands data on the socket. It can be
+ * read after accept(2).
+ */
+ATF_TC_WITHOUT_HEAD(send_before_accept);
+ATF_TC_BODY(send_before_accept, tc)
+{
+ const char buf[] = "hello";
+ char repl[sizeof(buf)];
+ const struct sockaddr_un *sun;
+ int l, s, a;
+
+ sun = mk_listening_socket(&l);
+
+ ATF_REQUIRE((s = socket(PF_LOCAL, SOCK_SEQPACKET, 0)) > 0);
+ ATF_REQUIRE(connect(s, (struct sockaddr *)sun, sizeof(*sun)) == 0);
+ ATF_REQUIRE(send(s, &buf, sizeof(buf), 0) == sizeof(buf));
+ ATF_REQUIRE((a = accept(l, NULL, NULL)) != 1);
+ ATF_REQUIRE(recv(a, &repl, sizeof(repl), 0) == sizeof(buf));
+ ATF_REQUIRE(strcmp(buf, repl) == 0);
+ close(l);
+ close(s);
+ close(a);
+}
+
/* accept(2) can receive a connection */
ATF_TC_WITHOUT_HEAD(accept);
ATF_TC_BODY(accept, tc)
@@ -1072,6 +1098,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, send_recv_nonblocking);
ATF_TP_ADD_TC(tp, send_recv_with_connect);
ATF_TP_ADD_TC(tp, sendto_recvfrom);
+ ATF_TP_ADD_TC(tp, send_before_accept);
ATF_TP_ADD_TC(tp, shutdown_send);
ATF_TP_ADD_TC(tp, shutdown_send_sigpipe);
ATF_TP_ADD_TC(tp, eagain_8k_8k);