chiark / gitweb /
Merge branches 'idx/verh' and 'idx/qmqpc'
[qmail] / timeoutread.c
1 #include "timeoutread.h"
2 #include "select.h"
3 #include "error.h"
4 #include "readwrite.h"
5
6 int timeoutread(t,fd,buf,len) int t; int fd; char *buf; int len;
7 {
8   fd_set rfds;
9   struct timeval tv;
10
11   tv.tv_sec = t;
12   tv.tv_usec = 0;
13
14   FD_ZERO(&rfds);
15   FD_SET(fd,&rfds);
16
17   if (select(fd + 1,&rfds,(fd_set *) 0,(fd_set *) 0,&tv) == -1) return -1;
18   if (FD_ISSET(fd,&rfds)) return read(fd,buf,len);
19
20   errno = error_timeout;
21   return -1;
22 }