libc: poll: handle POLLOUT better

This commit is contained in:
K. Lange 2023-04-18 08:58:10 +09:00
parent cc2fb582e9
commit 05b52800a0

View File

@ -5,6 +5,21 @@
extern char * _argv_0;
static char * poll_print_flags(int flags) {
static char buf[100];
char * b = buf;
int saw_something = 0;
#define OPT(n) do { if (flags & n) { b += sprintf(b, "%s%s", saw_something ? "|" : "", #n); saw_something = 1; } } while (0)
OPT(POLLIN);
OPT(POLLOUT);
OPT(POLLRDHUP);
OPT(POLLERR);
OPT(POLLHUP);
OPT(POLLNVAL);
OPT(POLLPRI);
return buf;
}
int poll(struct pollfd *fds, nfds_t nfds, int timeout) {
int count_pollin = 0;
@ -17,8 +32,15 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) {
for (nfds_t i = 0; i < nfds; ++i) {
if (fds[i].events & (~POLLIN)) {
fprintf(stderr, "%s: poll: unsupported bit set in fds (this implementation only supports POLLIN)\n", _argv_0);
return -EINVAL;
if (fds[i].events == (POLLIN | POLLPRI)) continue;
fprintf(stderr, "%s: poll: unsupported bit set in fds: %s\n", _argv_0, poll_print_flags(fds[i].events));
if ((fds[i].events & POLLOUT) && nfds == 1) {
fds[i].revents |= POLLOUT;
return 1;
}
//if (fds[i].events & POLLIN) continue;
//fprintf(stderr, "%s: poll: the above error is fatal\n", _argv_0);
//return -EINVAL;
}
}