diff options
author | Miguel Freitas <miguelfreitas@users.sourceforge.net> | 2003-02-05 00:08:55 +0000 |
---|---|---|
committer | Miguel Freitas <miguelfreitas@users.sourceforge.net> | 2003-02-05 00:08:55 +0000 |
commit | 4e0331fac2b197b5d6b20a987f2e54cff2f67ad4 (patch) | |
tree | 78ab654be8f591eb92f8cefa60bbaefdf306b678 | |
parent | 9cb0f1dd7c89891c6c80614ad13f4643ba00d566 (diff) | |
download | xine-lib-4e0331fac2b197b5d6b20a987f2e54cff2f67ad4.tar.gz xine-lib-4e0331fac2b197b5d6b20a987f2e54cff2f67ad4.tar.bz2 |
try to have the same behaviour reading from network on http/mms/pnm/rtsp.
select() is useful to avoid burning cpu cicles, otoh, we should not
call it after end of stream since it will hang xine for 30sec.
idea: do select() only on EAGAIN.
todo: unify these functions (?)
CVS patchset: 4105
CVS date: 2003/02/05 00:08:55
-rw-r--r-- | src/input/input_http.c | 24 | ||||
-rw-r--r-- | src/input/librtsp/rtsp.c | 32 | ||||
-rw-r--r-- | src/input/mms.c | 36 | ||||
-rw-r--r-- | src/input/mmsh.c | 34 | ||||
-rw-r--r-- | src/input/pnm.c | 36 |
5 files changed, 94 insertions, 68 deletions
diff --git a/src/input/input_http.c b/src/input/input_http.c index 9b21dde3d..05919863d 100644 --- a/src/input/input_http.c +++ b/src/input/input_http.c @@ -437,14 +437,24 @@ static off_t http_plugin_read (input_plugin_t *this_gen, /* read errors */ if (n < 0) { - switch (errno) { - case EAGAIN: - xine_log (this->stream->xine, XINE_LOG_MSG, _("input_http: EAGAIN\n")); - continue; - default: - xine_log (this->stream->xine, XINE_LOG_MSG, _("input_http: read error %d\n"), errno); - return 0; + if(errno == EAGAIN) { + fd_set rset; + struct timeval timeout; + + FD_ZERO (&rset); + FD_SET (this->fh, &rset); + + timeout.tv_sec = 30; + timeout.tv_usec = 0; + + if (select (this->fh+1, &rset, NULL, NULL, &timeout) <= 0) { + xine_log (this->stream->xine, XINE_LOG_MSG, _("input_http: timeout\n")); + return 0; + } + continue; } + xine_log (this->stream->xine, XINE_LOG_MSG, _("input_http: read error %d\n"), errno); + return 0; } num_bytes += n; diff --git a/src/input/librtsp/rtsp.c b/src/input/librtsp/rtsp.c index 06d0a9a70..c82439364 100644 --- a/src/input/librtsp/rtsp.c +++ b/src/input/librtsp/rtsp.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: rtsp.c,v 1.6 2003/01/29 10:49:24 miguelfreitas Exp $ + * $Id: rtsp.c,v 1.7 2003/02/05 00:08:55 miguelfreitas Exp $ * * a minimalistic implementation of rtsp protocol, * *not* RFC 2326 compilant yet. @@ -175,26 +175,24 @@ static ssize_t read_stream(int fd, void *buf, size_t count) { while (total < count) { -#if 0 - fd_set rset; - struct timeval timeout; - - FD_ZERO (&rset); - FD_SET (fd, &rset); - - timeout.tv_sec = 30; - timeout.tv_usec = 0; - - if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) { - return -1; - } -#endif - ret=read (fd, ((uint8_t*)buf)+total, count-total); if (ret<0) { - if(errno == EAGAIN) + if(errno == EAGAIN) { + fd_set rset; + struct timeval timeout; + + FD_ZERO (&rset); + FD_SET (fd, &rset); + + timeout.tv_sec = 30; + timeout.tv_usec = 0; + + if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) { + return -1; + } continue; + } printf ("rtsp: read error.\n"); return ret; diff --git a/src/input/mms.c b/src/input/mms.c index 6b5545577..e52f6277b 100644 --- a/src/input/mms.c +++ b/src/input/mms.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: mms.c,v 1.20 2003/01/31 14:06:17 miguelfreitas Exp $ + * $Id: mms.c,v 1.21 2003/02/05 00:10:30 miguelfreitas Exp $ * * based on work from major mms * utility functions to handle communication with an mms server @@ -112,26 +112,32 @@ static ssize_t read_timeout(int fd, void *buf, size_t count) { while (total < count) { - fd_set rset; - struct timeval timeout; - - FD_ZERO (&rset); - FD_SET (fd, &rset); - - timeout.tv_sec = 30; - timeout.tv_usec = 0; - - if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) { - return -1; - } - ret=read (fd, ((uint8_t*)buf)+total, count-total); - if (ret<=0) { + if (ret<0) { + if(errno == EAGAIN) { + fd_set rset; + struct timeval timeout; + + FD_ZERO (&rset); + FD_SET (fd, &rset); + + timeout.tv_sec = 30; + timeout.tv_usec = 0; + + if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) { + return -1; + } + continue; + } + printf ("mms: read error.\n"); return ret; } else total += ret; + + /* end of stream */ + if (!ret) break; } #ifdef LOG diff --git a/src/input/mmsh.c b/src/input/mmsh.c index db3a256c2..d75a7154e 100644 --- a/src/input/mmsh.c +++ b/src/input/mmsh.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: mmsh.c,v 1.10 2003/01/31 14:06:17 miguelfreitas Exp $ + * $Id: mmsh.c,v 1.11 2003/02/05 00:10:30 miguelfreitas Exp $ * * based on mms.c and specs from avifile * (http://avifile.sourceforge.net/asf-1.0.htm) @@ -180,28 +180,34 @@ static ssize_t read_timeout(int fd, void *buf, size_t count) { while (total < count) { - fd_set rset; - struct timeval timeout; + ret=read (fd, ((uint8_t*)buf)+total, count-total); - FD_ZERO (&rset); - FD_SET (fd, &rset); - - timeout.tv_sec = 30; - timeout.tv_usec = 0; + if (ret<0) { + if(errno == EAGAIN) { + fd_set rset; + struct timeval timeout; - if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) { - return -1; - } - - ret=read (fd, ((uint8_t*)buf)+total, count-total); + FD_ZERO (&rset); + FD_SET (fd, &rset); + + timeout.tv_sec = 30; + timeout.tv_usec = 0; + + if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) { + return -1; + } + continue; + } - if (ret<=0) { #ifdef LOG printf ("libmmsh: read error.\n"); #endif return ret; } else total += ret; + + /* end of stream */ + if (!ret) break; } #ifdef LOG diff --git a/src/input/pnm.c b/src/input/pnm.c index d0a9b0c9e..48aac07da 100644 --- a/src/input/pnm.c +++ b/src/input/pnm.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: pnm.c,v 1.11 2003/01/31 14:06:17 miguelfreitas Exp $ + * $Id: pnm.c,v 1.12 2003/02/05 00:10:30 miguelfreitas Exp $ * * pnm protocol implementation * based upon code from joschka @@ -265,26 +265,32 @@ static ssize_t rm_read(int fd, void *buf, size_t count) { while (total < count) { - fd_set rset; - struct timeval timeout; - - FD_ZERO (&rset); - FD_SET (fd, &rset); - - timeout.tv_sec = 3; - timeout.tv_usec = 0; - - if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) { - return -1; - } - ret=read (fd, ((uint8_t*)buf)+total, count-total); - if (ret<=0) { + if (ret<0) { + if(errno == EAGAIN) { + fd_set rset; + struct timeval timeout; + + FD_ZERO (&rset); + FD_SET (fd, &rset); + + timeout.tv_sec = 30; + timeout.tv_usec = 0; + + if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) { + return -1; + } + continue; + } + printf ("input_pnm: read error.\n"); return ret; } else total += ret; + + /* end of stream */ + if (!ret) break; } return total; |