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

From: Date: Fri, 30 Nov 2001 18:18:02 +0000
Subject: cvs: php4(PHP_4_0_7) /ext/sockets sockets.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-8338@lists.php.net to get a copy of this message
thies Fri Nov 30 13:18:02 2001 EDT Modified files: (Branch: PHP_4_0_7) /php4/ext/sockets sockets.c Log: MFH - make sockets extension usable Index: php4/ext/sockets/sockets.c diff -u php4/ext/sockets/sockets.c:1.61.2.4 php4/ext/sockets/sockets.c:1.61.2.5 --- php4/ext/sockets/sockets.c:1.61.2.4 Mon Nov 12 05:52:16 2001 +++ php4/ext/sockets/sockets.c Fri Nov 30 13:18:01 2001 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sockets.c,v 1.61.2.4 2001/11/12 10:52:16 dbeu Exp $ */ +/* $Id: sockets.c,v 1.61.2.5 2001/11/30 18:18:01 thies Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -430,6 +430,8 @@ php_fd_set *php_fd = (php_fd_set*)emalloc(sizeof(php_fd_set)); FD_ZERO(&(php_fd->set)); + + php_fd->max_fd = 0; ZEND_REGISTER_RESOURCE(return_value, php_fd, le_destroy); } @@ -557,6 +559,8 @@ FD_ZERO(&(php_fd->set)); + php_fd->max_fd = 0; + RETURN_TRUE; } /* }}} */ @@ -568,7 +572,7 @@ zval *arg1, *arg2, *arg3, *arg4; struct timeval tv; php_fd_set *rfds = NULL, *wfds = NULL, *xfds = NULL; - SOCKET max_fd; + SOCKET max_fd = 0; int sets = 0, usec = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r!r!r!z|l", &arg1, &arg2, &arg3, &arg4, &usec) == FAILURE) @@ -729,7 +733,8 @@ retval = send(php_sock->bsd_socket, str, min(length, str_len), 0); #endif - if (retval <= 0) { + if (retval < 0) { + php_sock->error = errno; php_error(E_WARNING, "%s() unable to write to socket %d [%d]: %s", get_active_function_name(TSRMLS_C), php_sock->bsd_socket, errno, php_strerror(errno)); RETURN_FALSE; } @@ -767,16 +772,15 @@ retval = recv(php_sock->bsd_socket, tmpbuf, length, 0); #endif - if (retval <= 0) { - if (retval != 0) { - /* Not EOF */ - PHP_SOCKET_ERROR(php_sock, "unable to read from socket", errno); - } + if (retval == -1) { + PHP_SOCKET_ERROR(php_sock, "unable to read from socket", errno); efree(tmpbuf); RETURN_FALSE; } + + tmpbuf = erealloc(tmpbuf, retval + 1); + tmpbuf[ retval ] = '\0' ; - tmpbuf[retval] = 0; RETURN_STRINGL(tmpbuf, retval, 0); } /* }}} */ @@ -958,7 +962,7 @@ } else { char *q = (char *) &(sin.sin_addr.s_addr); host_struct = gethostbyname(addr); - if (host_struct->h_addrtype != AF_INET) { + if ((! host_struct) || (host_struct->h_addrtype != AF_INET)) { RETURN_FALSE; }

« previous php.cvs (#8338) next »