Commit 23d7bef1 authored by Niels Möller's avatar Niels Möller
Browse files

Rerenamed poll.[ch]->jpoll.[ch].

Rev: src/configure.in:1.19
Rev: src/jpoll.c:1.3
Rev: src/jpoll.h:1.3
parent 834e570a
......@@ -74,7 +74,7 @@ dnl Some debian systems have both gmp1 and gmp2.
AC_CHECK_LIB(z, inflate, [], [with_zlib=no])
AC_CHECK_LIB(crypt, crypt)
AC_CHECK_LIB(xnet, inet_addr)
AC_CHECK_LIB(nsl, hostbyname)
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(socket, setsockopt)
dnl Checks for header files.
......@@ -114,7 +114,7 @@ AC_FUNC_VPRINTF
AC_CHECK_FUNCS(select socket strerror strtol)
AC_CHECK_FUNCS(getspnam)
AC_REPLACE_FUNCS(poll)
AC_CHECK_FUNCS(poll,,[LIBOBJS = jpoll.c $LIBOBJS])
dnl Check for broken shutdown
AC_CACHE_CHECK(for working shutdown on AF_UNIX sockets,
......
/* jpoll.c
*
* This code emulates a minimal poll() function, and can be used as a drop-in
* replacement for the SVID3 implementation. Note that at this time it only
* emulates the POLLIN and POLLOUT events.
*
* $id:$ */
/*
* AUTHOR: Sean Reifschneider <jafo@tummy.com>
* DATE: 1998-10-10
* COPYING: Free for unlimited use. No warranty expressed or implied.
* If it breaks, you get to keep both parts.
*/
#include "jpoll.h"
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
int poll(struct pollfd *fdlist, nfds_t count, int timeoutInMS)
{
struct timeval timeout, *to;
fd_set readfdset, writefdset;
nfds_t i;
int ret, fdcount = 0;
int tsize = getdtablesize();
if (timeoutInMS < 0)
to = NULL;
else {
to = &timeout;
timeout.tv_sec = timeoutInMS / 1000;
timeout.tv_usec = (timeoutInMS % 1000) * 1000;
}
FD_ZERO(&readfdset);
FD_ZERO(&writefdset);
for (i = 0; i < count; i++) {
if (fdlist[i].fd < 0) continue;
if (fdlist[i].events & POLLIN) FD_SET(fdlist[i].fd, &readfdset);
if (fdlist[i].events & POLLOUT) FD_SET(fdlist[i].fd, &writefdset);
fdcount++;
}
/* spec says that if all FDs are negative, then *ONLY* return zero */
if (fdcount == 0)
return(0);
/* clear all events */
for (i = 0; i < count; i++) fdlist[i].revents = 0;
if ((ret = select(tsize, &readfdset, &writefdset, NULL, &timeout)) == -1)
return(-1);
for (i = 0; i < count; i++) {
if (FD_ISSET(fdlist[i].fd, &readfdset)) fdlist[i].revents |= POLLIN;
if (FD_ISSET(fdlist[i].fd, &writefdset)) fdlist[i].revents |= POLLOUT;
printf("Set FD %d = %d\n", i, fdlist[i].revents);
}
printf("Returning %d\n", ret);
return(ret);
}
/* jpoll.h
*
* Header file for my poll() SVID3 emulation function.
*
* $Id$ */
/*
* AUTHOR: Sean Reifschneider <jafo@tummy.com>
* DATE: 1998-10-10
* Copyright (c) 1998 Sean Reifschneider
*
*/
#ifndef LSH_POLL_H_INCLUDED
#define LSH_POLL_H_INCLUDED
#define POLLIN 0x0001 /* check for input */
#define POLLOUT 0x0004 /* check for output */
struct pollfd {
int fd; /* file descriptor to poll */
short events; /* events we are interested in */
short revents; /* events that occured */
};
typedef unsigned int nfds_t;
int poll(struct pollfd *fdlist, nfds_t count, int timeoutInMS);
#endif /* LSH_POLL_H_INCLUDED */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment