summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2006-09-13 22:46:24 +0000
committerDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2006-09-13 22:46:24 +0000
commit4e4f09f3aab828c77afe0747ac86fcc3ea765416 (patch)
tree2a846ed4a0effe12755b0d141f2c9d32e2d1ebd6
parent58a0cc15a2b9120eadce685de9303e2f98c46115 (diff)
downloadxine-lib-4e4f09f3aab828c77afe0747ac86fcc3ea765416.tar.gz
xine-lib-4e4f09f3aab828c77afe0747ac86fcc3ea765416.tar.bz2
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
-rw-r--r--src/xine-engine/io_helper.c29
1 files changed, 22 insertions, 7 deletions
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;
}