From a100c25ea4b5864adc5203b6b979e8912062540a Mon Sep 17 00:00:00 2001 From: Gustavo Lopes Date: Fri, 1 Feb 2013 11:12:11 +0100 Subject: [PATCH 1/6] Fix overbroad skipif include --- ext/sockets/tests/ipv6_skipif.inc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ext/sockets/tests/ipv6_skipif.inc b/ext/sockets/tests/ipv6_skipif.inc index ad8cf77b357..1f824630cb8 100644 --- a/ext/sockets/tests/ipv6_skipif.inc +++ b/ext/sockets/tests/ipv6_skipif.inc @@ -2,7 +2,5 @@ if (!defined("AF_INET6")) { die('skip no IPv6 support'); } -/* If IPv6 is supported on the platform this will error out with code 111 - Connection refused. - If IPv6 is NOT supported, $errno will be set to something else (indicating parse/getaddrinfo error) */ -@stream_socket_client('tcp://[::1]:0', $errno); -if ($errno != 111) die('skip no IPv6 support'); +if (@stream_socket_client('udp://[::1]:8888') === false) + die('skip no IPv6 support'); From 97d656fc82104d9879b59dba9b80773346ec1f61 Mon Sep 17 00:00:00 2001 From: Gustavo Lopes Date: Fri, 1 Feb 2013 14:35:14 +0100 Subject: [PATCH 2/6] Move some declarations to sockets.c --- ext/sockets/php_sockets.h | 35 ----------------------------------- ext/sockets/sockets.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/ext/sockets/php_sockets.h b/ext/sockets/php_sockets.h index df205e5114d..2b6700d8838 100644 --- a/ext/sockets/php_sockets.h +++ b/ext/sockets/php_sockets.h @@ -37,41 +37,6 @@ extern zend_module_entry sockets_module_entry; #endif #endif -PHP_MINIT_FUNCTION(sockets); -PHP_MINFO_FUNCTION(sockets); -PHP_RSHUTDOWN_FUNCTION(sockets); - -PHP_FUNCTION(socket_select); -PHP_FUNCTION(socket_create_listen); -#ifdef HAVE_SOCKETPAIR -PHP_FUNCTION(socket_create_pair); -#endif -PHP_FUNCTION(socket_accept); -PHP_FUNCTION(socket_set_nonblock); -PHP_FUNCTION(socket_set_block); -PHP_FUNCTION(socket_listen); -PHP_FUNCTION(socket_close); -PHP_FUNCTION(socket_write); -PHP_FUNCTION(socket_read); -PHP_FUNCTION(socket_getsockname); -PHP_FUNCTION(socket_getpeername); -PHP_FUNCTION(socket_create); -PHP_FUNCTION(socket_connect); -PHP_FUNCTION(socket_strerror); -PHP_FUNCTION(socket_bind); -PHP_FUNCTION(socket_recv); -PHP_FUNCTION(socket_send); -PHP_FUNCTION(socket_recvfrom); -PHP_FUNCTION(socket_sendto); -PHP_FUNCTION(socket_get_option); -PHP_FUNCTION(socket_set_option); -#ifdef HAVE_SHUTDOWN -PHP_FUNCTION(socket_shutdown); -#endif -PHP_FUNCTION(socket_last_error); -PHP_FUNCTION(socket_clear_error); -PHP_FUNCTION(socket_import_stream); - #ifndef PHP_WIN32 typedef int PHP_SOCKET; # define PHP_SOCKETS_API PHPAPI diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 43bae9f6613..1cb36cd7eb3 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -279,6 +279,41 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_socket_import_stream, 0, 0, 1) ZEND_END_ARG_INFO() /* }}} */ +PHP_MINIT_FUNCTION(sockets); +PHP_MINFO_FUNCTION(sockets); +PHP_RSHUTDOWN_FUNCTION(sockets); + +PHP_FUNCTION(socket_select); +PHP_FUNCTION(socket_create_listen); +#ifdef HAVE_SOCKETPAIR +PHP_FUNCTION(socket_create_pair); +#endif +PHP_FUNCTION(socket_accept); +PHP_FUNCTION(socket_set_nonblock); +PHP_FUNCTION(socket_set_block); +PHP_FUNCTION(socket_listen); +PHP_FUNCTION(socket_close); +PHP_FUNCTION(socket_write); +PHP_FUNCTION(socket_read); +PHP_FUNCTION(socket_getsockname); +PHP_FUNCTION(socket_getpeername); +PHP_FUNCTION(socket_create); +PHP_FUNCTION(socket_connect); +PHP_FUNCTION(socket_strerror); +PHP_FUNCTION(socket_bind); +PHP_FUNCTION(socket_recv); +PHP_FUNCTION(socket_send); +PHP_FUNCTION(socket_recvfrom); +PHP_FUNCTION(socket_sendto); +PHP_FUNCTION(socket_get_option); +PHP_FUNCTION(socket_set_option); +#ifdef HAVE_SHUTDOWN +PHP_FUNCTION(socket_shutdown); +#endif +PHP_FUNCTION(socket_last_error); +PHP_FUNCTION(socket_clear_error); +PHP_FUNCTION(socket_import_stream); + /* {{{ sockets_functions[] */ const zend_function_entry sockets_functions[] = { From 9283b8aea4c681e39fed772543919bea4bba44a1 Mon Sep 17 00:00:00 2001 From: Gustavo Lopes Date: Fri, 1 Feb 2013 14:39:56 +0100 Subject: [PATCH 3/6] Move & improve PHP_SOCKET_ERROR def --- ext/sockets/php_sockets.h | 14 +++++++------- ext/sockets/sockets.c | 4 ---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/ext/sockets/php_sockets.h b/ext/sockets/php_sockets.h index 2b6700d8838..3762e026aa5 100644 --- a/ext/sockets/php_sockets.h +++ b/ext/sockets/php_sockets.h @@ -64,13 +64,13 @@ PHP_SOCKETS_API int php_sockets_le_socket(void); #define php_sockets_le_socket_name "Socket" -/* Prototypes */ -#ifdef ilia_0 /* not needed, only causes a compiler warning */ -static int php_open_listen_sock(php_socket **php_sock, int port, int backlog TSRMLS_DC); -static int php_accept_connect(php_socket *in_sock, php_socket **new_sock, struct sockaddr *la TSRMLS_DC); -static int php_read(php_socket *sock, void *buf, size_t maxlen, int flags); -static char *php_strerror(int error TSRMLS_DC); -#endif +#define PHP_SOCKET_ERROR(socket, msg, errn) \ + do { \ + int _err = (errn); /* save value to avoid repeated calls to WSAGetLastError() on Windows */ \ + (socket)->error = _err; \ + SOCKETS_G(last_error) = _err; \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s [%d]: %s", msg, _err, php_strerror(_err TSRMLS_CC)); \ + } while (0) ZEND_BEGIN_MODULE_GLOBALS(sockets) int last_error; diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 1cb36cd7eb3..6069fc5ec72 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -117,10 +117,6 @@ static char *php_strerror(int error TSRMLS_DC); #define PHP_NORMAL_READ 0x0001 #define PHP_BINARY_READ 0x0002 -#define PHP_SOCKET_ERROR(socket,msg,errn) socket->error = errn; \ - SOCKETS_G(last_error) = errn; \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s [%d]: %s", msg, errn, php_strerror(errn TSRMLS_CC)) - static int le_socket; #define le_socket_name php_sockets_le_socket_name From 24e380f97033b54ba0994fcf9f7c6c76111a3c93 Mon Sep 17 00:00:00 2001 From: Gustavo Lopes Date: Sat, 2 Feb 2013 12:44:00 +0100 Subject: [PATCH 4/6] Remove a Windows only warning --- main/network.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main/network.c b/main/network.c index 4b7a8d410ae..ba2ee1c4983 100644 --- a/main/network.c +++ b/main/network.c @@ -1076,11 +1076,6 @@ PHPAPI int php_set_sock_blocking(int socketd, int block TSRMLS_DC) /* with ioctlsocket, a non-zero sets nonblocking, a zero sets blocking */ flags = !block; if (ioctlsocket(socketd, FIONBIO, &flags) == SOCKET_ERROR) { - char *error_string; - - error_string = php_socket_strerror(WSAGetLastError(), NULL, 0); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", error_string); - efree(error_string); ret = FAILURE; } #else From 40663ede837c401212e950a3f65a7cd2885ccead Mon Sep 17 00:00:00 2001 From: Gustavo Lopes Date: Fri, 1 Feb 2013 14:58:35 +0100 Subject: [PATCH 5/6] Fix tests (Windows) --- .../tests/socket_import_stream-4-win.phpt | 3 - ...socket_sentto_recvfrom_ipv6_udp-win32.phpt | 62 +++++++++++++++++++ .../socket_sentto_recvfrom_ipv6_udp.phpt | 3 + 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp-win32.phpt diff --git a/ext/sockets/tests/socket_import_stream-4-win.phpt b/ext/sockets/tests/socket_import_stream-4-win.phpt index e2fc523ce58..b36764f6177 100644 --- a/ext/sockets/tests/socket_import_stream-4-win.phpt +++ b/ext/sockets/tests/socket_import_stream-4-win.phpt @@ -80,9 +80,6 @@ stream_set_blocking Warning: stream_set_blocking(): %d is not a valid stream resource in %s on line %d socket_set_block -Warning: socket_set_block(): An operation was attempted on something that is not a socket. - in %ssocket_import_stream-4-win.php on line %d - Warning: socket_set_block(): unable to set blocking mode [%d]: An operation was attempted on something that is not a socket. in %ssocket_import_stream-4-win.php on line %d diff --git a/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp-win32.phpt b/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp-win32.phpt new file mode 100644 index 00000000000..ec965094bcc --- /dev/null +++ b/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp-win32.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test if socket_recvfrom() receives data sent by socket_sendto() via IPv6 UDP (Win32) +--SKIPIF-- + +PHP Testfest Berlin 2009-05-09 diff --git a/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp.phpt b/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp.phpt index 04f62eddd37..2beb8080cdb 100644 --- a/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp.phpt +++ b/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp.phpt @@ -5,6 +5,9 @@ Test if socket_recvfrom() receives data sent by socket_sendto() via IPv6 UDP if (!extension_loaded('sockets')) { die('SKIP The sockets extension is not loaded.'); } +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Not valid for Windows'); +} require 'ipv6_skipif.inc'; --FILE-- Date: Fri, 1 Feb 2013 16:38:54 +0100 Subject: [PATCH 6/6] Fix wrong blocking state being set --- ext/sockets/sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 6069fc5ec72..c6c5477967c 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -1126,7 +1126,7 @@ PHP_FUNCTION(socket_set_nonblock) if (stream != NULL) { if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, 0, NULL) != -1) { - php_sock->blocking = 1; + php_sock->blocking = 0; RETURN_TRUE; } }