diff options
| author | manuel <manuel@mausz.at> | 2013-02-04 00:08:53 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-02-04 00:08:53 +0100 |
| commit | 69aec538b456402170dc723af417ba5c05389c32 (patch) | |
| tree | e6f34c543f17c6392447ea337b2e2868212424d1 /timeoutread.c | |
| download | qmail-69aec538b456402170dc723af417ba5c05389c32.tar.gz qmail-69aec538b456402170dc723af417ba5c05389c32.tar.bz2 qmail-69aec538b456402170dc723af417ba5c05389c32.zip | |
qmail 1.03 import
Diffstat (limited to 'timeoutread.c')
| -rw-r--r-- | timeoutread.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/timeoutread.c b/timeoutread.c new file mode 100644 index 0000000..c75e29c --- /dev/null +++ b/timeoutread.c | |||
| @@ -0,0 +1,22 @@ | |||
| 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 | } | ||
