mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Fix polling of files on Windows
This commit is contained in:
parent
0f3457c172
commit
6f868fe1de
2 changed files with 36 additions and 1 deletions
|
@ -179,7 +179,7 @@ textwindows static int sys_poll_nt_impl(struct pollfd *fds, uint64_t nfds,
|
|||
|
||||
// check input status of pipes / consoles without blocking
|
||||
// this ensures any socket fds won't starve them of events
|
||||
// if a file handle is POLLOUT only, we just mark it ready
|
||||
// we can't poll file handles, so we just mark those ready
|
||||
for (i = 0; i < pn; ++i) {
|
||||
fi = fileindices[i];
|
||||
ev = fds[fi].events;
|
||||
|
@ -215,6 +215,8 @@ textwindows static int sys_poll_nt_impl(struct pollfd *fds, uint64_t nfds,
|
|||
fds[fi].revents = fds[fi].events & (POLLRDNORM_ | POLLWRNORM_);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
fds[fi].revents = fds[fi].events & (POLLRDNORM_ | POLLWRNORM_);
|
||||
}
|
||||
rc += !!fds[fi].revents;
|
||||
}
|
||||
|
|
|
@ -310,6 +310,39 @@ TEST(poll, pipein_pollout_blocks) {
|
|||
EXPECT_SYS(0, 0, close(pipefds[0]));
|
||||
}
|
||||
|
||||
TEST(poll, pipein_file_noblock) {
|
||||
if (IsFreebsd() || IsOpenbsd())
|
||||
return;
|
||||
int pipefds[2];
|
||||
EXPECT_SYS(0, 3, open("boop", O_CREAT | O_RDWR | O_TRUNC, 0644));
|
||||
EXPECT_SYS(0, 0, pipe(pipefds));
|
||||
struct pollfd fds[] = {{pipefds[0], POLLIN}, {3, POLLIN}};
|
||||
EXPECT_SYS(0, 1, poll(fds, 2, -1u));
|
||||
EXPECT_TRUE(!!(fds[1].revents & POLLIN));
|
||||
EXPECT_TRUE(!(fds[1].revents & POLLOUT));
|
||||
EXPECT_SYS(0, 0, close(pipefds[1]));
|
||||
EXPECT_SYS(0, 0, close(pipefds[0]));
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(poll, pipein_file_noblock2) {
|
||||
if (IsFreebsd() || IsOpenbsd())
|
||||
return;
|
||||
int pipefds[2];
|
||||
EXPECT_SYS(0, 3, open("boop", O_CREAT | O_RDWR | O_TRUNC, 0644));
|
||||
EXPECT_SYS(0, 0, pipe(pipefds));
|
||||
EXPECT_SYS(0, 1, write(5, "x", 1));
|
||||
struct pollfd fds[] = {{pipefds[0], POLLIN}, {3, POLLIN | POLLOUT}};
|
||||
EXPECT_SYS(0, 2, poll(fds, 2, -1u));
|
||||
EXPECT_TRUE(!!(fds[0].revents & POLLIN));
|
||||
EXPECT_TRUE(!(fds[0].revents & POLLOUT));
|
||||
EXPECT_TRUE(!!(fds[1].revents & POLLIN));
|
||||
EXPECT_TRUE(!!(fds[1].revents & POLLOUT));
|
||||
EXPECT_SYS(0, 0, close(pipefds[1]));
|
||||
EXPECT_SYS(0, 0, close(pipefds[0]));
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(poll, pipeout_pollout) {
|
||||
int pipefds[2];
|
||||
EXPECT_SYS(0, 0, pipe(pipefds));
|
||||
|
|
Loading…
Reference in a new issue