cvs: php4(PHP_4_2_0) /ext/sockets sockets.c

From: Date: Sat, 09 Mar 2002 07:20:35 +0000
Subject: cvs: php4(PHP_4_2_0) /ext/sockets sockets.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-9846@lists.php.net to get a copy of this message
jason Sat Mar 9 02:20:35 2002 EDT Modified files: (Branch: PHP_4_2_0) /php4/ext/sockets sockets.c Log: MFH: Recent Bug Fixes Index: php4/ext/sockets/sockets.c diff -u php4/ext/sockets/sockets.c:1.95 php4/ext/sockets/sockets.c:1.95.2.1 --- php4/ext/sockets/sockets.c:1.95 Wed Mar 6 15:19:09 2002 +++ php4/ext/sockets/sockets.c Sat Mar 9 02:20:35 2002 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sockets.c,v 1.95 2002/03/06 20:19:09 jason Exp $ */ +/* $Id: sockets.c,v 1.95.2.1 2002/03/09 07:20:35 jason Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -100,6 +100,9 @@ static unsigned char second_and_third_args_force_ref[] = {3, BYREF_NONE, BYREF_FORCE, BYREF_FORCE}; +static unsigned char second_arg_of_four_force_ref[] = +{4, BYREF_NONE, BYREF_FORCE, BYREF_NONE, BYREF_NONE}; + static unsigned char second_fifth_and_sixth_args_force_ref[] = {6, BYREF_NONE, BYREF_FORCE, BYREF_NONE, BYREF_NONE, BYREF_FORCE, BYREF_FORCE}; @@ -131,7 +134,7 @@ PHP_FE(socket_connect, NULL) PHP_FE(socket_strerror, NULL) PHP_FE(socket_bind, NULL) - PHP_FE(socket_recv, second_arg_force_ref) + PHP_FE(socket_recv, second_arg_of_four_force_ref) PHP_FE(socket_send, NULL) PHP_FE(socket_recvfrom, second_fifth_and_sixth_args_force_ref) PHP_FE(socket_sendto, NULL) @@ -432,7 +435,7 @@ } /* }}} */ -int php_sock_array_to_fd_set(zval *sock_array, fd_set *fds, int *max_fd TSRMLS_DC) { +int php_sock_array_to_fd_set(zval *sock_array, fd_set *fds, SOCKET *max_fd TSRMLS_DC) { zval **element; php_socket *php_sock; @@ -489,13 +492,14 @@ Runs the select() system call on the sets mentioned with a timeout specified by tv_sec and tv_usec */ PHP_FUNCTION(socket_select) { - zval *r_array, *w_array, *e_array; + zval *r_array, *w_array, *e_array, *sec; struct timeval tv; + struct timeval *tv_p=NULL; fd_set rfds, wfds, efds; SOCKET max_fd = 0; - int retval, sets = 0, usec = 0, sec=0; + int retval, sets = 0, usec = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!a!l|l", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!a!z!|l", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE) return; FD_ZERO(&rfds); @@ -511,17 +515,26 @@ RETURN_FALSE; } - tv.tv_sec = sec; - tv.tv_usec = usec; - - retval = select(max_fd+1, &rfds, &wfds, &efds, &tv); - + /* If seconds is not set to null, build the timeval, else we wait indefinitely */ + if (sec != NULL) { + convert_to_long_ex(&sec); + tv.tv_sec = Z_LVAL_P(sec); + tv.tv_usec = usec; + tv_p=&tv; + } + + retval = select(max_fd+1, &rfds, &wfds, &efds, tv_p); + + if (retval == -1) { + php_error(E_WARNING, "%s() %s [%d]: %s", get_active_function_name(TSRMLS_C), "unable to select", errno, php_strerror(errno)); + RETURN_FALSE; + } + if (r_array != NULL) php_sock_array_from_fd_set(r_array, &rfds TSRMLS_CC); if (w_array != NULL) php_sock_array_from_fd_set(w_array, &wfds TSRMLS_CC); if (e_array != NULL) php_sock_array_from_fd_set(e_array, &efds TSRMLS_CC); - RETURN_LONG(retval); - + RETURN_LONG(retval); } /* }}} */ @@ -888,8 +901,6 @@ php_socket *php_sock; struct sockaddr_in sin; struct sockaddr_un s_un; - struct in_addr addr_buf; - struct hostent *host_struct; char *addr; int retval, addr_len, port; @@ -1243,8 +1254,6 @@ memset(recv_buf, 0, len + 1); if ((retval = recv(php_sock->bsd_socket, recv_buf, len, flags)) < 1) { - if (retval == -1) PHP_SOCKET_ERROR(php_sock, "unable to read from socket", errno); - efree(recv_buf); zval_dtor(buf); @@ -1259,7 +1268,12 @@ Z_STRLEN_P(buf)=retval; Z_TYPE_P(buf)=IS_STRING; } - + + if (retval == -1) { + PHP_SOCKET_ERROR(php_sock, "unable to read from socket", errno); + RETURN_FALSE; + } + RETURN_LONG(retval); } /* }}} */ @@ -1279,7 +1293,12 @@ ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); retval = send(php_sock->bsd_socket, buf, (buf_len < len ? buf_len : len), flags); - + + if (retval == -1) { + PHP_SOCKET_ERROR(php_sock, "unable to write to socket", errno); + RETURN_FALSE; + } + RETURN_LONG(retval); } /* }}} */ @@ -1366,7 +1385,6 @@ php_socket *php_sock; struct sockaddr_un s_un; struct sockaddr_in sin; - struct in_addr addr_buf; int retval, buf_len, len, flags, addr_len, port = 0; char *buf, *addr; @@ -1402,7 +1420,12 @@ break; default: - RETURN_LONG(0); + RETURN_FALSE; + } + + if (retval == -1) { + PHP_SOCKET_ERROR(php_sock, "unable to write to socket", errno); + RETURN_FALSE; } RETURN_LONG(retval); @@ -1893,7 +1916,6 @@ { zval *arg1; php_socket *php_sock; - int error; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) return;

« previous php.cvs (#9846) next »