Commit: f082d6311b7998987f018fc6c791dd1892f2912a Author: Anatol Belski <a...@php.net> Mon, 22 Apr 2013 18:53:52 +0200 Parents: 70b67f2e509ca05e60c85cc14c1b82b107713604 Branches: PHP-5.3 PHP-5.4 PHP-5.5 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f082d6311b7998987f018fc6c791dd1892f2912a Log: Fixed stream_socket_pair() on Windows x64 and improved errorhandling in the socketpair() implementation. Changed paths: M NEWS M ext/standard/streamsfuncs.c M win32/sockets.c Diff: diff --git a/NEWS b/NEWS index a5cd7f2..0876c1e 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,10 @@ PHP NEWS . Fixed bug #64342 (ZipArchive::addFile() has to check for file existence). (Anatol) +- Streams: + . Fixed Windows x64 version of stream_socket_pair() and improved error handling + (Anatol Belski) + 11 Apr 2013, PHP 5.3.24 - Core diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 4a86007..27042f6 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -51,7 +51,7 @@ PHP_FUNCTION(stream_socket_pair) { long domain, type, protocol; php_stream *s1, *s2; - int pair[2]; + php_socket_t pair[2]; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &domain, &type, &protocol)) { diff --git a/win32/sockets.c b/win32/sockets.c index d642808..c8fddd6 100644 --- a/win32/sockets.c +++ b/win32/sockets.c @@ -39,33 +39,54 @@ PHPAPI int socketpair(int domain, int type, int protocol, SOCKET sock[2]) return -1; } + sock[0] = sock[1] = redirect = INVALID_SOCKET; - sock[0] = socket(domain, type, protocol); - address.sin_addr.s_addr = INADDR_ANY; - address.sin_family = AF_INET; - address.sin_port = 0; - bind(sock[0], (struct sockaddr*)&address, sizeof(address)); + sock[0] = socket(domain, type, protocol); + if (INVALID_SOCKET == sock[0]) { + goto error; + } + + address.sin_addr.s_addr = INADDR_ANY; + address.sin_family = AF_INET; + address.sin_port = 0; + + if (bind(sock[0], (struct sockaddr*)&address, sizeof(address)) != 0) { + goto error; + } if(getsockname(sock[0], (struct sockaddr *)&address, &size) != 0) { + goto error; + } + + if (listen(sock[0], 2) != 0) { + goto error; + } + + sock[1] = socket(domain, type, protocol); + if (INVALID_SOCKET == sock[1]) { + goto error; } - listen(sock[0], 2); - sock[1] = socket(domain, type, protocol); address.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + if(connect(sock[1], (struct sockaddr*)&address, sizeof(address)) != 0) { + goto error; + } - connect(sock[1], (struct sockaddr*)&address, sizeof(address)); redirect = accept(sock[0],(struct sockaddr*)&address, &size); + if (INVALID_SOCKET == redirect) { + goto error; + } closesocket(sock[0]); sock[0] = redirect; - if(sock[0] == INVALID_SOCKET ) { - closesocket(sock[0]); - closesocket(sock[1]); - WSASetLastError(WSAECONNABORTED); - return -1; - } - return 0; + +error: + closesocket(redirect); + closesocket(sock[0]); + closesocket(sock[1]); + WSASetLastError(WSAECONNABORTED); + return -1; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php