Commit | Line | Data |
---|---|---|
2117e02e MW |
1 | #include "timeoutwrite.h" |
2 | #include "select.h" | |
3 | #include "error.h" | |
4 | #include "readwrite.h" | |
5 | ||
212b6f5d | 6 | int timeoutwrite(t,fd,buf,len) int t; int fd; char *buf; int len; |
2117e02e MW |
7 | { |
8 | fd_set wfds; | |
9 | struct timeval tv; | |
2117e02e | 10 | |
212b6f5d | 11 | tv.tv_sec = t; |
2117e02e MW |
12 | tv.tv_usec = 0; |
13 | ||
2117e02e MW |
14 | FD_ZERO(&wfds); |
15 | FD_SET(fd,&wfds); | |
16 | ||
17 | if (select(fd + 1,(fd_set *) 0,&wfds,(fd_set *) 0,&tv) == -1) return -1; | |
18 | if (FD_ISSET(fd,&wfds)) return write(fd,buf,len); | |
19 | ||
2117e02e MW |
20 | errno = error_timeout; |
21 | return -1; | |
22 | } |