chiark / gitweb /
Upstream qmail 1.01
[qmail] / timeoutwrite.c
1 #include "timeoutwrite.h"
2 #include "select.h"
3 #include "error.h"
4 #include "readwrite.h"
5
6 int timeoutwrite(fdt,buf,len) int fdt; char *buf; int len;
7 {
8   fd_set wfds;
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(&wfds);
17   FD_SET(fd,&wfds);
18
19   if (select(fd + 1,(fd_set *) 0,&wfds,(fd_set *) 0,&tv) == -1) return -1;
20   if (FD_ISSET(fd,&wfds)) return write(fd,buf,len);
21
22   shutdown(fd,1);
23   errno = error_timeout;
24   return -1;
25 }