diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2002-11-26 18:32:00 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2002-11-26 18:32:00 +0000 |
commit | 9e248ff645ace5434c25604f09818ec3e9e65655 (patch) | |
tree | d68e00e50f6ff340f951e81014bc51d38d15beb7 /regress | |
parent | a66dd816f81a28df633744f22cb2100389e756f9 (diff) |
test for working timeouts on recv, currently failing
Diffstat (limited to 'regress')
-rw-r--r-- | regress/sys/kern/Makefile | 3 | ||||
-rw-r--r-- | regress/sys/kern/rcvtimeo/Makefile | 6 | ||||
-rw-r--r-- | regress/sys/kern/rcvtimeo/rcvtimeo.c | 74 |
3 files changed, 82 insertions, 1 deletions
diff --git a/regress/sys/kern/Makefile b/regress/sys/kern/Makefile index ab08538f4eb..3a3917e3d0e 100644 --- a/regress/sys/kern/Makefile +++ b/regress/sys/kern/Makefile @@ -1,9 +1,10 @@ -# $OpenBSD: Makefile,v 1.39 2002/08/31 22:56:01 mickey Exp $ +# $OpenBSD: Makefile,v 1.40 2002/11/26 18:31:59 mickey Exp $ SUBDIR+= execve getrusage kqueue mmap mmap2 mmap3 dup2 minherit rlimit-file SUBDIR+= fcntl_dup dup2_self pread preadv exit pwrite pwritev SUBDIR+= syscall __syscall unfdpass accept nanosleep sysvmsg sysvsem SUBDIR+= sysvshm rfork gettimeofday signal exec_self noexec +SUBDIR+= rcvtimeo install: diff --git a/regress/sys/kern/rcvtimeo/Makefile b/regress/sys/kern/rcvtimeo/Makefile new file mode 100644 index 00000000000..73e736d564b --- /dev/null +++ b/regress/sys/kern/rcvtimeo/Makefile @@ -0,0 +1,6 @@ +# $OpenBSD: Makefile,v 1.1 2002/11/26 18:31:59 mickey Exp $ + +PROG= rcvtimeo +CFLAGS+=-Wall + +.include <bsd.regress.mk> diff --git a/regress/sys/kern/rcvtimeo/rcvtimeo.c b/regress/sys/kern/rcvtimeo/rcvtimeo.c new file mode 100644 index 00000000000..ed23bc090d6 --- /dev/null +++ b/regress/sys/kern/rcvtimeo/rcvtimeo.c @@ -0,0 +1,74 @@ +/* $OpenBSD: rcvtimeo.c,v 1.1 2002/11/26 18:31:59 mickey Exp $ */ + +/* Copyright (c) 2002 Michael Shalayeff. Public Domain */ + +#include <sys/param.h> +#include <sys/socket.h> + +#include <netinet/in.h> + +#include <signal.h> +#include <unistd.h> +#include <stdio.h> +#include <errno.h> +#include <err.h> + +volatile int back; + +void +sigalarm(int sig, siginfo_t *sip, void *scp) +{ + if (!back) + _exit(1); +} + +int +main(int argc, char *argv[]) +{ + struct sockaddr_in sin; + struct sigaction sa; + struct timeval tv; + u_char buf[16]; + int s; + + sa.sa_sigaction = &sigalarm; + sa.sa_flags = SA_SIGINFO; + sigemptyset(&sa.sa_mask); + sigaction(SIGALRM, &sa, NULL); + + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + err(1, "socket"); + + sin.sin_len = sizeof(sin); + sin.sin_family = AF_INET; + sin.sin_port = htons(30000); /* XXX assuming nothing is there */ + sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) + err(1, "bind"); + + tv.tv_sec = 1; + tv.tv_usec = 0; + if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) + err(1, "setsockopt1"); + + back = 0; + alarm(2); + errno = 0; + if (recv(s, buf, sizeof(buf), 0) < 0 && errno != EAGAIN) + err(1, "recv1"); + back = 1; + + tv.tv_sec = 0; + tv.tv_usec = 1; + if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) + err(1, "setsockopt2"); + + back = 0; + alarm(2); + errno = 0; + if (recv(s, buf, sizeof(buf), 0) < 0 && errno != EAGAIN) + err(1, "recv2"); + back = 1; + + exit (0); +} |