fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
timeout.c
Go to the documentation of this file.
1#include <unistd.h>
2#include "error.h"
3#include "iopause.h"
4#include "timeout.h"
5
14int timeoutread(int t,int fd,char *buf,int len)
15{
16 struct taia now;
17 struct taia deadline;
18 iopause_fd x;
19
20 taia_now(&now);
21 taia_uint(&deadline,t);
22 taia_add(&deadline,&now,&deadline);
23
24 x.fd = fd;
25 x.events = IOPAUSE_READ;
26 for (;;) {
27 taia_now(&now);
28 iopause(&x,1,&deadline,&now);
29 if (x.revents) break;
30 if (taia_less(&deadline,&now)) {
31 errno = ETIMEDOUT;
32 return -1;
33 }
34 }
35 return read(fd,buf,len);
36}
37
38int timeoutwrite(int t,int fd,char *buf,int len)
39{
40 struct taia now;
41 struct taia deadline;
42 iopause_fd x;
43
44 taia_now(&now);
45 taia_uint(&deadline,t);
46 taia_add(&deadline,&now,&deadline);
47
48 x.fd = fd;
49 x.events = IOPAUSE_WRITE;
50 for (;;) {
51 taia_now(&now);
52 iopause(&x,1,&deadline,&now);
53 if (x.revents) break;
54 if (taia_less(&deadline,&now)) {
55 errno = ETIMEDOUT;
56 return -1;
57 }
58 }
59 return write(fd,buf,len);
60}
int read(int _str, void *_buf, int _b)
int timeoutwrite(int t, int fd, char *buf, int len)
Definition: timeout.c:38
int timeoutread(int t, int fd, char *buf, int len)
Definition: timeout.c:14
#define IOPAUSE_READ
Definition: iopause.h:19
#define IOPAUSE_WRITE
Definition: iopause.h:20
int iopause(iopause_fd *, unsigned int, struct taia *, struct taia *)
Definition: iopause.c:14
int taia_less(struct taia *, struct taia *)
Definition: taia.c:39
void taia_add(struct taia *, struct taia *, struct taia *)
Definition: taia.c:14
void taia_uint(struct taia *, unsigned int)
Definition: taia.c:99
int taia_now(struct taia *)
Definition: taia.c:48
Definition: taia.h:13