From: Darren S. <li...@yo...> - 2008-04-05 23:29:23
|
# HG changeset patch # User Darren Salt <li...@yo...> # Date 1207438129 -3600 # Node ID 38bf5c25bf55a16098bccf9c5c5fef77c4f3ad07 # Parent 4b15aef158f373a24b244c8e78e13647a8c4fc7a Timeout fixups for when loading a playlist MRL over HTTP. This is a workaround. If you're compiling for use with xine-lib 1.2, configuring with --disable-own-playlist-parsers may be a better option. diff -r 38bf5c25bf55a16098bccf9c5c5fef77c4f3ad07 -r 4b15aef158f373a24b244c8e78e13647a8c4fc7a ChangeLog --- a/ChangeLog Sun Apr 06 00:28:49 2008 +0100 +++ b/ChangeLog Sat Mar 29 14:59:53 2008 +0000 @@ -3,6 +3,10 @@ 0.5.902: 2008/??/?? * Fixed MIME type breakage in gxine.desktop. * Fixed init with LIRC running but no valid remote control. (Workaround for a LIRC bug.) + * Timeout fixups for when loading a playlist MRL over HTTP. + (This is a workaround. If you're compiling for use with xine-lib + 1.2, configuring with --disable-own-playlist-parsers may be a + better option.) 0.5.901: 2008/03/08 [dsalt] diff -r 38bf5c25bf55a16098bccf9c5c5fef77c4f3ad07 -r 4b15aef158f373a24b244c8e78e13647a8c4fc7a src/http.c --- a/src/http.c Sun Apr 06 00:28:49 2008 +0100 +++ b/src/http.c Sat Mar 29 14:59:53 2008 +0000 @@ -33,11 +33,14 @@ #include <unistd.h> #include <ctype.h> #include <errno.h> +#include <poll.h> +#include <time.h> #include <netinet/in.h> #include "http.h" #include "utils.h" +#include "watchdog.h" /* #define LOG @@ -98,16 +101,53 @@ static int http_host_connect_attempt (st sin.i.sin_addr = ia; sin.i.sin_port = htons(port); - if (connect (s, &sin.s, sizeof (sin))==-1 - && errno != EINPROGRESS) - { - display_error (FROM_GXINE, _("HTTP error"), - _("Cannot connect to host: %s"), strerror (errno)); - close (s); - return -1; - } - - return s; + int blocking = fcntl (s, F_SETFL, fcntl (s, F_GETFL) | O_NONBLOCK) == -1; + if (blocking) + watchdog_off (); + + if (!connect (s, &sin.s, sizeof (sin))) + { + if (blocking) + watchdog_on (); + return s; + } + + if (errno != EINPROGRESS) + goto fail; + + /* if we get here, we have a non-blocking socket not yet connected */ + + struct pollfd fd = { s, POLLIN | POLLPRI | POLLOUT | POLLERR | POLLHUP }; + + time_t start = time (NULL); + do + { + switch (poll (&fd, 1, 1000)) + { + case -1: + goto fail; + case 0: + do_pending_events (); + continue; + default: + if (fd.revents & POLLERR) + goto fail; + if (fd.revents & POLLHUP) + { + errno = ETIMEDOUT; /* or something */ + goto fail; + } + return s; + } + } while (time (NULL) - start < 30); + + fail: + display_error (FROM_GXINE, _("HTTP error"), + _("Cannot connect to host: %s"), strerror (errno)); + close (s); + if (blocking) + watchdog_on (); + return -1; } static int http_host_connect (const char *host, int port) diff -r 38bf5c25bf55a16098bccf9c5c5fef77c4f3ad07 -r 4b15aef158f373a24b244c8e78e13647a8c4fc7a src/watchdog.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/watchdog.h Sat Mar 29 14:59:53 2008 +0000 @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2008 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + +#ifndef GXINE_WATCHDOG_H +#define GXINE_WATCHDOG_H + +#include "config.h" + +#ifdef WITH_WATCHDOG +# define watchdog_off() alarm (0) +# define watchdog_on() alarm (30) +#else +# define watchdog_off() do {} while (0) +# define watchdog_on() do {} while (0) +#endif + +#endif |