diff options
author | phintuka <phintuka> | 2006-08-23 06:46:00 +0000 |
---|---|---|
committer | phintuka <phintuka> | 2006-08-23 06:46:00 +0000 |
commit | 70dcc1222853937bfd7c971ac0a7bb1513769e83 (patch) | |
tree | dddeab2be3ad28d770ef83964b783dac614f610c | |
parent | b38741b75431cb1e1cabeeee61b5a1fb63eda186 (diff) | |
download | xineliboutput-70dcc1222853937bfd7c971ac0a7bb1513769e83.tar.gz xineliboutput-70dcc1222853937bfd7c971ac0a7bb1513769e83.tar.bz2 |
timed_read
-rw-r--r-- | tools/cxsocket.h | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/tools/cxsocket.h b/tools/cxsocket.h index 4d4da731..086e3b11 100644 --- a/tools/cxsocket.h +++ b/tools/cxsocket.h @@ -4,7 +4,7 @@ * See the main source file 'xineliboutput.c' for copyright information and * how to reach the author. * - * $Id: cxsocket.h,v 1.7 2006-08-15 16:35:15 phintuka Exp $ + * $Id: cxsocket.h,v 1.8 2006-08-23 06:46:00 phintuka Exp $ * */ @@ -162,6 +162,39 @@ static inline ssize_t timed_write(int fd, const void *buffer, size_t size, return written; } +static inline ssize_t timed_read(int fd, void *buffer, size_t size, + int timeout_ms) +{ + ssize_t missing = (ssize_t)size; + unsigned char *ptr = (unsigned char *)buffer; + cPoller poller(fd); + + while (missing > 0) { + + if(!poller.Poll(timeout_ms)) { + LOGERR("timed_read: poll() failed at %d/%d", size-missing, size); + return size-missing; + } + + errno = 0; + ssize_t p = read(fd, ptr, missing); + + if (p <= 0) { + if (errno == EINTR || errno == EAGAIN) { + LOGDBG("timed_read: EINTR/EAGAIN during read(), retrying"); + continue; + } + LOGERR("timed_read: read() error at %d/%d", size-missing, size); + return size-missing; + } + + ptr += p; + missing -= p; + } + + return size; +} + //#include "xine_osd_command.h" static inline int write_osd_command(int fd, osd_command_t *cmd) |