diff --git a/src/modules/files/file.c b/src/modules/files/file.c index e729a61ca7d75598c8c97db8ca5376fd9071e122..fee7a5a3c257765ac11ac878d95a381ff9a06f9d 100644 --- a/src/modules/files/file.c +++ b/src/modules/files/file.c @@ -5,7 +5,7 @@ \*/ #include "global.h" -RCSID("$Id: file.c,v 1.107 1998/07/09 01:39:15 hubbe Exp $"); +RCSID("$Id: file.c,v 1.108 1998/07/09 01:56:35 hubbe Exp $"); #include "fdlib.h" #include "interpret.h" #include "svalue.h" @@ -658,33 +658,61 @@ static void file_read(INT32 args) push_int(0); } +#ifdef HAVE_AND_USE_POLL +#include <poll.h> +#else + #ifdef HAVE_SYS_SELECT_H #include <sys/select.h> #endif +#endif #ifndef __NT__ static void file_peek(INT32 args) { +#ifdef HAVE_AND_USE_POLL + struct pollfd fds; + int ret; + + fds.fd=THIS->fd; + fds.events=POLLIN; + fds.revents=0; + + THREADS_ALLOW(); + ret=poll(&fds, 1, 0); + THREADS_DISALLOW(); + + if(ret < 0) + { + ERRNO=errno; + ret=-1; + }else{ + ret = ret>=0 && (fds.revents & POLLIN); + } +#else int ret; fd_set tmp; struct timeval tv; + tv.tv_usec=0; tv.tv_sec=0; fd_FD_ZERO(&tmp); fd_FD_SET(ret=THIS->fd, &tmp); + THREADS_ALLOW(); ret=select(ret+1,&tmp,0,0,&tv); THREADS_DISALLOW(); - pop_n_elems(args); - if(ret < 0) { ERRNO=errno; - push_int(-1); + ret=-1; }else{ - push_int( ret>0 && fd_FD_ISSET(THIS->fd, &tmp)); + ret= ret>0 && fd_FD_ISSET(THIS->fd, &tmp); } +#endif + pop_n_elems(args); + push_int(ret); } #endif