Commit | Line | Data |
---|---|---|
dc0d77d7 CE |
1 | #include <unistd.h> |
2 | #include "error.h" | |
3 | #include "iopause.h" | |
4 | #include "timeoutwrite.h" | |
5 | ||
6 | int timeoutwrite(int t,int fd,char *buf,int len) | |
7 | { | |
8 | struct taia now; | |
9 | struct taia deadline; | |
10 | iopause_fd x; | |
11 | ||
12 | taia_now(&now); | |
13 | taia_uint(&deadline,t); | |
14 | taia_add(&deadline,&now,&deadline); | |
15 | ||
16 | x.fd = fd; | |
17 | x.events = IOPAUSE_WRITE; | |
18 | for (;;) { | |
19 | taia_now(&now); | |
20 | iopause(&x,1,&deadline,&now); | |
21 | if (x.revents) break; | |
22 | if (taia_less(&deadline,&now)) { | |
23 | errno = error_timeout; | |
24 | return -1; | |
25 | } | |
26 | } | |
27 | return write(fd,buf,len); | |
28 | } |