cvs: php4 /ext/sockets sockets.c
| From: | Markus Fischer | Date: | Wed, 01 May 2002 10:41:12 +0000 |
| Subject: | cvs: php4 /ext/sockets sockets.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-11589@lists.php.net to get a copy of this message | ||
mfischer Wed May 1 06:41:12 2002 EDT
Modified files:
/php4/ext/sockets sockets.c
Log:
- Fix couple of problems with socket_create_pair():
- Force fourth argument to be passed by reference
- Since the argument is modified there is no need to force it to be an array
since it's destroyed anyway
- Only modify the argument if socketpair() was successfully
- Fix string modified for error message message
- Set global last_error when socketpair() fails
Index: php4/ext/sockets/sockets.c
diff -u php4/ext/sockets/sockets.c:1.105 php4/ext/sockets/sockets.c:1.106
--- php4/ext/sockets/sockets.c:1.105 Wed May 1 05:25:26 2002
+++ php4/ext/sockets/sockets.c Wed May 1 06:41:10 2002
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: sockets.c,v 1.105 2002/05/01 09:25:26 mfischer Exp $ */
+/* $Id: sockets.c,v 1.106 2002/05/01 10:41:10 mfischer Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -103,6 +103,9 @@
static unsigned char second_arg_of_four_force_ref[] =
{4, BYREF_NONE, BYREF_FORCE, BYREF_NONE, BYREF_NONE};
+static unsigned char fourth_arg_force_ref[] =
+{3, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE};
+
static unsigned char second_fifth_and_sixth_args_force_ref[] =
{6, BYREF_NONE, BYREF_FORCE, BYREF_NONE, BYREF_NONE, BYREF_FORCE, BYREF_FORCE};
@@ -121,7 +124,7 @@
PHP_FE(socket_select, first_through_third_args_force_ref)
PHP_FE(socket_create, NULL)
PHP_FE(socket_create_listen, NULL)
- PHP_FE(socket_create_pair, NULL)
+ PHP_FE(socket_create_pair, fourth_arg_force_ref)
PHP_FE(socket_accept, NULL)
PHP_FE(socket_set_nonblock, NULL)
PHP_FE(socket_set_block, NULL)
@@ -1853,7 +1856,7 @@
SOCKET fds_array[2];
int domain, type, protocol;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llla", &domain, &type,
&protocol, &fds_array_zval) == FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllz", &domain, &type,
&protocol, &fds_array_zval) == FAILURE)
return;
php_sock[0] = (php_socket*)emalloc(sizeof(php_socket));
@@ -1865,20 +1868,21 @@
}
if (type > 10) {
- php_error(E_WARNING, "%d() invalid socket type [%d] specified for argument 2, assuming
SOCK_STREAM", get_active_function_name(TSRMLS_C), type);
+ php_error(E_WARNING, "%s() invalid socket type [%d] specified for argument 2, assuming
SOCK_STREAM", get_active_function_name(TSRMLS_C), type);
type = SOCK_STREAM;
}
- zval_dtor(fds_array_zval);
- if (array_init(fds_array_zval) == FAILURE) {
- php_error(E_WARNING, "%s() can't initialize fds array",
get_active_function_name(TSRMLS_C));
+ if (socketpair(domain, type, protocol, fds_array) != 0) {
+ SOCKETS_G(last_error) = errno;
+ php_error(E_WARNING, "%s() unable to create socket pair [%d]: %s",
get_active_function_name(TSRMLS_C), errno, php_strerror(errno));
efree(php_sock[0]);
efree(php_sock[1]);
RETURN_FALSE;
}
- if (socketpair(domain, type, protocol, fds_array) != 0) {
- php_error(E_WARNING, "%s() unable to create socket pair [%d]: %s",
get_active_function_name(TSRMLS_C), errno, php_strerror(errno));
+ zval_dtor(fds_array_zval);
+ if (array_init(fds_array_zval) == FAILURE) {
+ php_error(E_WARNING, "%s() can't initialize array for 3rd argument",
get_active_function_name(TSRMLS_C));
efree(php_sock[0]);
efree(php_sock[1]);
RETURN_FALSE;