diff --git a/ext/sockets/php_sockets.h b/ext/sockets/php_sockets.h index df205e5114d..3762e026aa5 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 @@ -99,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 5d09ad7fa97..33d8a09d7d5 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -118,10 +118,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 @@ -280,6 +276,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[] = { @@ -1096,7 +1127,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; } } 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'); 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--