Skip to content

Commit

Permalink
iopause: assume poll() is available
Browse files Browse the repository at this point in the history
Since poll() is available on all platforms we care about, we don't need to
check if it is.

This gets rid of trypoll.c, the last configure-time check that required to be
run on the host (messing with cross). We also get rid of trysysel.c, since
select() was only used as a fallback when poll() isn't avaialble.
  • Loading branch information
0x5c committed Apr 4, 2023
1 parent 006296c commit 819cd66
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 161 deletions.
39 changes: 0 additions & 39 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -426,25 +426,6 @@ if test -n "$HASDIRENT"; then
echo "CPPFLAGS += -DHASDIRENT" >> $CONFIG_MK
fi

#
# Check for sys/dirent.h.
#
printf "Checking for sys/select.h ... "
if test -n "$HASSYSSEL"; then
echo "yes (cached)."
else
if $XCC configure_tests/trysysel.c -o trysysel 2>/dev/null; then
echo yes.
HASSYSSEL=1
else
echo no.
fi
rm -f trysysel
fi
if test -n "$HASSYSSEL"; then
echo "CPPFLAGS += -DHASSYSSEL" >> $CONFIG_MK
fi

#
# Check for one argument reboot().
#
Expand All @@ -464,26 +445,6 @@ if test -n "$HASONEARGREBOOT"; then
echo "CPPFLAGS += -DHASONEARGREBOOT" >> $CONFIG_MK
fi

#
# Check for suitable poll().
# XXX: Very bad, this should not need to run. Do we have alternatives?
#
printf "Checking for suitable poll() ... "
if test -n "$HASGOODPOLL"; then
echo "yes (cached)."
else
if $XCC configure_tests/trypoll.c -o trypoll 2>/dev/null && ./trypoll; then
echo yes.
HASGOODPOLL=1
else
echo no.
fi
rm -f trypoll
fi
if test -n "$HASGOODPOLL"; then
echo "CPPFLAGS += -DHASGOODPOLL" >> $CONFIG_MK
fi

# If --enable-static enabled, build static binaries.
if [ "$BUILD_STATIC" = "yes" ]; then
echo "BUILD_STATIC = -static" >>$CONFIG_MK
Expand Down
21 changes: 0 additions & 21 deletions configure_tests/trypoll.c

This file was deleted.

11 changes: 0 additions & 11 deletions configure_tests/trysysel.c

This file was deleted.

47 changes: 0 additions & 47 deletions src/iopause.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* Public domain. */

#include "taia.h"
#include "select.h"
#include "iopause.h"

void iopause(iopause_fd *x,unsigned int len,struct taia *deadline,struct taia *stamp)
Expand All @@ -24,55 +23,9 @@ void iopause(iopause_fd *x,unsigned int len,struct taia *deadline,struct taia *s
for (i = 0;i < len;++i)
x[i].revents = 0;

#ifdef IOPAUSE_POLL

poll(x,len,millisecs);
/* XXX: some kernels apparently need x[0] even if len is 0 */
/* XXX: how to handle EAGAIN? are kernels really this dumb? */
/* XXX: how to handle EINVAL? when exactly can this happen? */

#else
{

struct timeval tv;
fd_set rfds;
fd_set wfds;
int nfds;
int fd;

FD_ZERO(&rfds);
FD_ZERO(&wfds);

nfds = 1;
for (i = 0;i < len;++i) {
fd = x[i].fd;
if (fd < 0) continue;
if (fd >= 8 * sizeof(fd_set)) continue; /*XXX*/

if (fd >= nfds) nfds = fd + 1;
if (x[i].events & IOPAUSE_READ) FD_SET(fd,&rfds);
if (x[i].events & IOPAUSE_WRITE) FD_SET(fd,&wfds);
}

tv.tv_sec = millisecs / 1000;
tv.tv_usec = 1000 * (millisecs % 1000);

if (select(nfds,&rfds,&wfds,(fd_set *) 0,&tv) <= 0)
return;
/* XXX: for EBADF, could seek out and destroy the bad descriptor */

for (i = 0;i < len;++i) {
fd = x[i].fd;
if (fd < 0) continue;
if (fd >= 8 * sizeof(fd_set)) continue; /*XXX*/

if (x[i].events & IOPAUSE_READ)
if (FD_ISSET(fd,&rfds)) x[i].revents |= IOPAUSE_READ;
if (x[i].events & IOPAUSE_WRITE)
if (FD_ISSET(fd,&wfds)) x[i].revents |= IOPAUSE_WRITE;
}

}
#endif

}
17 changes: 0 additions & 17 deletions src/iopause.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,13 @@
#ifndef IOPAUSE_H
#define IOPAUSE_H

#ifdef HASGOODPOLL

#define IOPAUSE_POLL

#include <sys/types.h>
#include <poll.h>

typedef struct pollfd iopause_fd;
#define IOPAUSE_READ POLLIN
#define IOPAUSE_WRITE POLLOUT

#else

typedef struct {
int fd;
short events;
short revents;
} iopause_fd;

#define IOPAUSE_READ 1
#define IOPAUSE_WRITE 4

#endif

#include "taia.h"

extern void iopause(iopause_fd *,unsigned int,struct taia *,struct taia *);
Expand Down
11 changes: 0 additions & 11 deletions src/runit.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ int main (int argc, const char * const *argv, char * const *envp) {
int wstat;
int st;
iopause_fd x;
#ifndef IOPAUSE_POLL
fd_set rfds;
struct timeval t;
#endif
char ch;
int ttyfd;
struct stat s;
Expand Down Expand Up @@ -152,14 +148,7 @@ int main (int argc, const char * const *argv, char * const *envp) {
sig_unblock(sig_child);
sig_unblock(sig_cont);
sig_unblock(sig_int);
#ifdef IOPAUSE_POLL
poll(&x, 1, 14000);
#else
t.tv_sec =14; t.tv_usec =0;
FD_ZERO(&rfds);
FD_SET(x.fd, &rfds);
select(x.fd +1, &rfds, (fd_set*)0, (fd_set*)0, &t);
#endif
sig_block(sig_cont);
sig_block(sig_child);
sig_block(sig_int);
Expand Down
15 changes: 0 additions & 15 deletions src/select.h

This file was deleted.

0 comments on commit 819cd66

Please sign in to comment.