From 61d7ecbdc2efe104a76dcb1689e98185a383bbf2 Mon Sep 17 00:00:00 2001 From: leitner Date: Sat, 6 Sep 2003 00:52:11 +0000 Subject: [PATCH] add epoll and kqueue tests --- GNUmakefile | 14 ++++++++++++++ tryepoll.c | 18 ++++++++++++++++++ trykqueue.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 tryepoll.c create mode 100644 trykqueue.c diff --git a/GNUmakefile b/GNUmakefile index 8ab8a06..90cb1cc 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -155,6 +155,20 @@ haveinline.h: tryinline.c if ! $(DIET) $(CC) $(CFLAGS) -c tryinline.c >/dev/null 2>&1; then echo "#define inline"; fi > $@ -rm -f tryinline.o +havekqueue.h: trykqueue.c + -rm -f $@ + if $(DIET) $(CC) $(CFLAGS) -c trykqueue.c >/dev/null 2>&1; then echo "#define HAVE_KQUEUE"; fi > $@ + -rm -f trykqueue.o + +haveepoll.h: tryepoll.c + -rm -f $@ + if $(DIET) $(CC) $(CFLAGS) -o tryepoll tryepoll.c >/dev/null 2>&1; then echo "#define HAVE_EPOLL 1"; else \ + if $(DIET) $(CC) $(CFLAGS) -o tryepoll tryepoll.c -lepoll >/dev/null 2>&1; then echo "#define HAVE_EPOLL 2"; fi; fi > $@ + -rm -f tryepoll + +libepoll: haveepoll.h + test "`cat haveepoll.h`" = "#define HAVE_EPOLL 2" && echo -lepoll > $@ + iopause.h: iopause.h1 iopause.h2 trypoll.c -rm -f $@ if $(DIET) $(CC) $(CFLAGS) -o t trypoll.c >/dev/null 2>&1; then cp iopause.h2 iopause.h; else cp iopause.h1 iopause.h; fi diff --git a/tryepoll.c b/tryepoll.c new file mode 100644 index 0000000..6fe7485 --- /dev/null +++ b/tryepoll.c @@ -0,0 +1,18 @@ +#include +#include + +int main() { + int efd=epoll_create(10); + struct epoll_event x; + if (efd==-1) return 111; + x.events=EPOLLIN; + x.data.fd=0; + if (epoll_ctl(efd,EPOLL_CTL_ADD,0 /* fd */,&x)==-1) return 111; + { + int i,n; + struct epoll_event y[100]; + if ((n=epoll_wait(efd,y,100,1000))==-1) return 111; + if (n>0) + printf("event %d on fd #%d\n",y[0].events,y[0].data.fd); + } +} diff --git a/trykqueue.c b/trykqueue.c new file mode 100644 index 0000000..1874b64 --- /dev/null +++ b/trykqueue.c @@ -0,0 +1,29 @@ +#include +#include +#include + +int main() { + int kq=kqueue(); + struct kevent kev; + struct timespec ts; + if (kq==-1) return 111; + EV_SET(&kev, 0 /* fd */, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0); + ts.tv_sec=0; ts.tv_nsec=0; + if (kevent(kq,&kev,1,0,0,&ts)==-1) return 111; + + { + struct kevent events[100]; + int i,n; + ts.tv_sec=1; ts.tv_nsec=0; + switch (n=kevent(kq,0,0,events,100,&ts)) { + case -1: return 111; + case 0: puts("no data on fd #0"); break; + } + for (i=0; i