diff options
-rw-r--r-- | src/xine-engine/demux.c | 65 | ||||
-rw-r--r-- | src/xine-engine/xine_internal.h | 4 |
2 files changed, 68 insertions, 1 deletions
diff --git a/src/xine-engine/demux.c b/src/xine-engine/demux.c index 5fd21ba41..c1b78dcd8 100644 --- a/src/xine-engine/demux.c +++ b/src/xine-engine/demux.c @@ -27,6 +27,10 @@ #include <string.h> #include <pthread.h> #include <sched.h> +#include <sys/time.h> +#include <sys/types.h> +#include <unistd.h> +#include <errno.h> #include "xine_internal.h" #include "demuxers/demux.h" #include "buffer.h" @@ -327,3 +331,64 @@ int xine_demux_stop_thread (xine_stream_t *stream) { return 0; } + + +/* + * read from socket/file descriptor checking demux_action_pending + * + * network input plugins should use this function in order to + * not freeze the engine. + * + * aborts with zero if no data is available and demux_action_pending is set + */ +off_t xine_read_abort (xine_stream_t *stream, int fd, char *buf, off_t todo) { + + off_t ret, total; + + total = 0; + + while (total < todo) { + + fd_set rset; + struct timeval timeout; + + while(1) { + + FD_ZERO (&rset); + FD_SET (fd, &rset); + + timeout.tv_sec = 0; + timeout.tv_usec = 50000; + + if( select (fd+1, &rset, NULL, NULL, &timeout) <= 0 ) { + /* aborts current read if action pending. otherwise xine + * cannot be stopped when no more data is available. + */ + if( stream->demux_action_pending ) + return 0; + } else { + break; + } + } + + ret = read (fd, &buf[total], todo - total); + + /* check EOF */ + if (!ret) + break; + + /* check errors */ + if(ret < 0) { + if(errno == EAGAIN) + continue; + + perror("xine_read_abort"); + return ret; + } + + total += ret; + } + + return total; +} + diff --git a/src/xine-engine/xine_internal.h b/src/xine-engine/xine_internal.h index 3564e598c..45291cea4 100644 --- a/src/xine-engine/xine_internal.h +++ b/src/xine-engine/xine_internal.h @@ -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: xine_internal.h,v 1.133 2003/04/05 12:28:16 miguelfreitas Exp $ + * $Id: xine_internal.h,v 1.134 2003/04/13 16:28:48 miguelfreitas Exp $ * */ @@ -307,6 +307,8 @@ void xine_demux_control_end (xine_stream_t *stream, uint32_t flags); int xine_demux_start_thread (xine_stream_t *stream); int xine_demux_stop_thread (xine_stream_t *stream); +off_t xine_read_abort (xine_stream_t *stream, int fd, char *buf, off_t todo); + /* * plugin_loader functions * |