linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* epoll: different edge-triggered behavior bewteen pipe and socketpair
@ 2021-02-16 19:39 Francesco Ruggeri
  0 siblings, 0 replies; only message in thread
From: Francesco Ruggeri @ 2021-02-16 19:39 UTC (permalink / raw)
  To: netdev, linux-kselftest, linux-kernel, linux-fsdevel, viro, fruggeri

pipe() and socketpair() have different behavior wrt edge-triggered
read epoll, in that no event is generated when data is written into
a non-empty pipe, but an event is generated if socketpair() is used
instead.
This simple modification of the epoll2 testlet from 
tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c
(it just adds a second write) shows the different behavior.
The testlet passes with pipe() but fails with socketpair() with 5.10.
They both fail with 4.19.
Is it fair to assume that 5.10 pipe's behavior is the correct one?

Thanks,
Francesco Ruggeri

/*
 *          t0
 *           | (ew)
 *          e0
 *           | (et)
 *          s0
 */
TEST(epoll2)
{
	int efd;
	int sfd[2];
	struct epoll_event e;

	ASSERT_EQ(socketpair(AF_UNIX, SOCK_STREAM, 0, sfd), 0);
	//ASSERT_EQ(pipe(sfd), 0);

	efd = epoll_create(1);
	ASSERT_GE(efd, 0);

	e.events = EPOLLIN | EPOLLET;
	ASSERT_EQ(epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e), 0);

	ASSERT_EQ(write(sfd[1], "w", 1), 1);
	EXPECT_EQ(epoll_wait(efd, &e, 1, 0), 1);

	ASSERT_EQ(write(sfd[1], "w", 1), 1);
	EXPECT_EQ(epoll_wait(efd, &e, 1, 0), 0);

	close(efd);
	close(sfd[0]);
	close(sfd[1]);
}



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-02-16 19:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-16 19:39 epoll: different edge-triggered behavior bewteen pipe and socketpair Francesco Ruggeri

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).