Upstream qmail 1.01
[qmail] / timeoutread.c
1 #include "timeoutread.h"
2 #include "select.h"
3 #include "error.h"
4 #include "readwrite.h"
5
6 int timeoutread(fdt,buf,len) int fdt; char *buf; int len;
7 {
8 fd_set rfds;
9 struct timeval tv;
10 int fd;
11
12 tv.tv_sec = (fdt >> 10);
13 tv.tv_usec = 0;
14
15 fd = (fdt & 1023);
16 FD_ZERO(&rfds);
17 FD_SET(fd,&rfds);
18
19 if (select(fd + 1,&rfds,(fd_set *) 0,(fd_set *) 0,&tv) == -1) return -1;
20 if (FD_ISSET(fd,&rfds)) return read(fd,buf,len);
21
22 shutdown(fd,0);
23 errno = error_timeout;
24 return -1;
25 }