epoll: different edge-triggered behavior bewteen pipe and socketpair

From: Francesco Ruggeri
Date: Tue Feb 16 2021 - 14:51:07 EST


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]);
}