From 4e4f09f3aab828c77afe0747ac86fcc3ea765416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 13 Sep 2006 22:46:24 +0000 Subject: When only one host is present, or with the last host, enable the non-block mode, as we don't care anymore if it fails or not. This allows a way shorter timeout when trying to connect directly to an IPv4 address (the given timeout rather than 4 minutes). CVS patchset: 8227 CVS date: 2006/09/13 22:46:24 --- src/xine-engine/io_helper.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/xine-engine/io_helper.c b/src/xine-engine/io_helper.c index 064a8b338..3e72ed47c 100644 --- a/src/xine-engine/io_helper.c +++ b/src/xine-engine/io_helper.c @@ -152,15 +152,31 @@ int _x_io_tcp_connect(xine_stream_t *stream, const char *host, int port) { continue; } - /** - * Uncommenting nonblocking features due to IPv6 support. - * Need to know if the connect failed, in order to try another - * address (if available). Error will be reported if no address - * worked. + /* + * Enable the non-blocking features only when there's no other + * address, allowing to use other addresses if available. + * there will be an error if no address worked at all */ - + if ( ! tmpaddr->ai_next ) { #ifndef WIN32 + if (fcntl (s, F_SETFL, fcntl (s, F_GETFL) | O_NONBLOCK) == -1) { + _x_message(stream, XINE_MSG_CONNECTION_REFUSED, "can't put socket in non-blocking mode", strerror(errno), NULL); + return -1; + } +#else + unsigned long non_block = 1; + int rc; + + rc = ioctlsocket(s, FIONBIO, &non_block); + if (rc == SOCKET_ERROR) { + _x_message(stream, XINE_MSG_CONNECTION_REFUSED, "can't put socket in non-blocking mode", strerror(errno), NULL); + return -1; + } +#endif + } + +#ifndef WIN32 if (connect(s, tmpaddr->ai_addr, tmpaddr->ai_addrlen)==-1 && errno != EINPROGRESS) { @@ -178,7 +194,6 @@ int _x_io_tcp_connect(xine_stream_t *stream, const char *host, int port) { tmpaddr = tmpaddr->ai_next; continue; } else { - return s; } -- cgit v1.2.3