From f696aece3f1247cecd1852a1e0f68fa47adf7301 Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Tue, 7 Sep 2010 09:47:36 +0000 Subject: [PATCH] - fix bug #50953, socket will not connect to IPv4 address when the host has both ipv4 and ipv6 addresses --- NEWS | 2 ++ main/network.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 53682df488..61d7cfe3ab 100644 --- a/NEWS +++ b/NEWS @@ -72,6 +72,8 @@ - Fixed bug #50481 (Storing many SPLFixedArray in an array crashes). (Felipe) - Fixed bug #52260 (dns_get_record fails with non-existing domain on Windows). (a_jelly_doughnut at phpbb dot com, Pierre) +- Fixed #50953, socket will not connect to IPv4 address when the host has both + IPv4 and IPv6 addresses, on Windows. (Gustavo, Pierre) 22 Jul 2010, PHP 5.3.3 - Upgraded bundled sqlite to version 3.6.23.1. (Ilia) diff --git a/main/network.c b/main/network.c index 32337d2f44..3ebc1506cd 100644 --- a/main/network.c +++ b/main/network.c @@ -206,7 +206,7 @@ static int php_network_getaddresses(const char *host, int socktype, struct socka } hints.ai_family = ipv6_borked ? AF_INET : AF_UNSPEC; # endif - + if ((n = getaddrinfo(host, NULL, &hints, &res))) { if (error_string) { spprintf(error_string, 0, "php_network_getaddresses: getaddrinfo failed: %s", PHP_GAI_STRERROR(n)); @@ -337,9 +337,19 @@ PHPAPI int php_network_connect_socket(php_socket_t sockfd, if (n == 0) { goto ok; } - +# ifdef PHP_WIN32 + /* The documentation for connect() says in case of non-blocking connections + * the select function reports success in the writefds set and failure in + * the exceptfds set. Indeed, using PHP_POLLREADABLE results in select + * failing only due to the timeout and not immediately as would be + * exepected when a connection is actively refused. This way, + * php_pollfd_for will return a mask with POLLOUT if the connection + * is successful and with POLLPRI otherwise. */ + if ((n = php_pollfd_for(sockfd, POLLOUT|POLLPRI, timeout)) == 0) { +#else if ((n = php_pollfd_for(sockfd, PHP_POLLREADABLE|POLLOUT, timeout)) == 0) { error = PHP_TIMEOUT_ERROR_VALUE; +#endif } if (n > 0) { -- 2.40.0