add epoll and kqueue tests

master
leitner 21 years ago
parent 149c908c8a
commit 61d7ecbdc2

@ -155,6 +155,20 @@ haveinline.h: tryinline.c
if ! $(DIET) $(CC) $(CFLAGS) -c tryinline.c >/dev/null 2>&1; then echo "#define inline"; fi > $@ if ! $(DIET) $(CC) $(CFLAGS) -c tryinline.c >/dev/null 2>&1; then echo "#define inline"; fi > $@
-rm -f tryinline.o -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 iopause.h: iopause.h1 iopause.h2 trypoll.c
-rm -f $@ -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 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

@ -0,0 +1,18 @@
#include <inttypes.h>
#include <sys/epoll.h>
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);
}
}

@ -0,0 +1,29 @@
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
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<n; ++i) {
printf("ident %d, filter %d, flags %d, fflags %d, data %d\n",
events[i].ident,events[i].filter,events[i].flags,
events[i].fflags,events[i].data);
}
}
return 0;
}
Loading…
Cancel
Save