use a pipe instead of sched_yield()
This commit is contained in:
parent
b43f86b836
commit
7085ce980b
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: t_sendrecv.c,v 1.6 2019/02/03 03:19:28 mrg Exp $ */
|
||||
/* $NetBSD: t_sendrecv.c,v 1.7 2021/03/21 16:58:07 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2018 The NetBSD Foundation, Inc.
|
||||
|
@ -29,7 +29,7 @@
|
|||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: t_sendrecv.c,v 1.6 2019/02/03 03:19:28 mrg Exp $");
|
||||
__RCSID("$NetBSD: t_sendrecv.c,v 1.7 2021/03/21 16:58:07 christos Exp $");
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -41,7 +41,6 @@ __RCSID("$NetBSD: t_sendrecv.c,v 1.6 2019/02/03 03:19:28 mrg Exp $");
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sched.h>
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
|
@ -62,33 +61,33 @@ handle_sigchld(__unused int pid)
|
|||
}
|
||||
|
||||
static void
|
||||
sender(int fd)
|
||||
sender(int sd)
|
||||
{
|
||||
union packet p;
|
||||
ssize_t n;
|
||||
p.seq = 0;
|
||||
for (size_t i = 0; i < COUNT; i++) {
|
||||
for (; (n = send(fd, &p, sizeof(p), 0)) == sizeof(p);
|
||||
for (; (n = send(sd, &p, sizeof(p), 0)) == sizeof(p);
|
||||
p.seq++)
|
||||
continue;
|
||||
printf(">>%zd %d %ju\n", n, errno, p.seq);
|
||||
// printf(">>%zd %d %ju\n", n, errno, p.seq);
|
||||
ATF_REQUIRE_MSG(errno == ENOBUFS, "send %s", strerror(errno));
|
||||
// sched_yield();
|
||||
}
|
||||
printf("sender done\n");
|
||||
close(sd);
|
||||
// printf("sender done\n");
|
||||
}
|
||||
|
||||
static void
|
||||
receiver(int fd)
|
||||
receiver(int sd)
|
||||
{
|
||||
union packet p;
|
||||
ssize_t n;
|
||||
uintmax_t seq = 0;
|
||||
|
||||
do {
|
||||
for (size_t i = 0; i < COUNT; i++) {
|
||||
if (rdied)
|
||||
return;
|
||||
while ((n = recv(fd, &p, sizeof(p), 0), sizeof(p))
|
||||
while ((n = recv(sd, &p, sizeof(p), 0), sizeof(p))
|
||||
== sizeof(p))
|
||||
{
|
||||
if (rdied)
|
||||
|
@ -97,26 +96,29 @@ receiver(int fd)
|
|||
printf("%ju != %ju\n", p.seq, seq);
|
||||
seq = p.seq + 1;
|
||||
}
|
||||
printf("<<%zd %d %ju\n", n, errno, seq);
|
||||
// printf("<<%zd %d %ju\n", n, errno, seq);
|
||||
if (n == 0)
|
||||
return;
|
||||
ATF_REQUIRE_EQ(n, -1);
|
||||
ATF_REQUIRE_MSG(errno == ENOBUFS, "recv %s", strerror(errno));
|
||||
} while (p.seq < COUNT);
|
||||
}
|
||||
close(sd);
|
||||
}
|
||||
|
||||
static void
|
||||
sendrecv(int rerror)
|
||||
{
|
||||
int fd[2], error;
|
||||
int fd[2], sd[2], error;
|
||||
char c = 0;
|
||||
struct sigaction sa;
|
||||
|
||||
error = socketpair(AF_UNIX, SOCK_DGRAM, 0, fd);
|
||||
// error = pipe(fd);
|
||||
error = socketpair(AF_UNIX, SOCK_DGRAM, 0, sd);
|
||||
ATF_REQUIRE_MSG(error != -1, "socketpair failed (%s)", strerror(errno));
|
||||
error = pipe(fd);
|
||||
ATF_REQUIRE_MSG(error != -1, "pipe failed (%s)", strerror(errno));
|
||||
|
||||
for (size_t i = 0; i < __arraycount(fd); i++) {
|
||||
error = setsockopt(fd[i], SOL_SOCKET, SO_RERROR, &rerror,
|
||||
for (size_t i = 0; i < __arraycount(sd); i++) {
|
||||
error = setsockopt(sd[i], SOL_SOCKET, SO_RERROR, &rerror,
|
||||
sizeof(rerror));
|
||||
ATF_REQUIRE_MSG(error != -1,
|
||||
"setsockopt(SO_RERROR) failed (%s)", strerror(errno));
|
||||
|
@ -133,17 +135,18 @@ sendrecv(int rerror)
|
|||
switch (fork()) {
|
||||
case -1:
|
||||
ATF_REQUIRE_MSG(errno == 0,
|
||||
"socketpair failed (%s)", strerror(errno));
|
||||
"fork failed (%s)", strerror(errno));
|
||||
__unreachable();
|
||||
/*NOTREACHED*/
|
||||
case 0:
|
||||
sched_yield();
|
||||
sender(fd[0]);
|
||||
close(fd[0]);
|
||||
read(fd[1], &c, sizeof(c));
|
||||
sender(sd[0]);
|
||||
close(sd[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
default:
|
||||
receiver(fd[1]);
|
||||
write(fd[0], &c, sizeof(c));
|
||||
receiver(sd[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue