cvs: php4 /ext/sockets sockets.c

From: Date: Mon, 21 May 2001 17:48:19 +0000
Subject: cvs: php4 /ext/sockets sockets.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-5900@lists.php.net to get a copy of this message
sterling Mon May 21 10:48:19 2001 EDT Modified files: /php4/ext/sockets sockets.c Log: Fix socket_read to work under Linux again. Index: php4/ext/sockets/sockets.c diff -u php4/ext/sockets/sockets.c:1.38 php4/ext/sockets/sockets.c:1.39 --- php4/ext/sockets/sockets.c:1.38 Mon May 21 10:34:18 2001 +++ php4/ext/sockets/sockets.c Mon May 21 10:48:19 2001 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sockets.c,v 1.38 2001/05/21 17:34:18 sterling Exp $ */ +/* $Id: sockets.c,v 1.39 2001/05/21 17:48:19 sterling Exp $ */ #include "php.h" @@ -239,14 +239,14 @@ } /* php_read -- wrapper around read() so that it only reads to a \r or \n. */ -int php_read(php_socket *php_sock, void *buf, int maxlen) +int php_read(int socket, void *buf, int maxlen) { int m = 0, n = 0; int no_read = 0; int nonblock = 0; char *t = (char *) buf; - m = fcntl(php_sock->socket, F_GETFL); + m = fcntl(socket, F_GETFL); if (m < 0) { return m; } @@ -276,7 +276,7 @@ } if (n < maxlen) { - m = read(php_sock->socket, (void *) t, 1); + m = read(socket, (void *) t, 1); } if (errno != 0 && errno != ESPIPE && errno != EAGAIN) { @@ -641,6 +641,8 @@ } /* }}} */ +typedef int (*read_function)(int, void *, int); + /* {{{ proto mixed socket_read(resource socket, int length [, int type]) Reads length bytes from socket */ PHP_FUNCTION(socket_read) @@ -648,7 +650,7 @@ zval **arg1, **arg2, **arg3; char *tmpbuf; php_socket *php_sock; - int (*read_function)(int, void *, int) = (int (*)(int, void *, int)) php_read; + read_function php_read; int retval, argc = ZEND_NUM_ARGS(); if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &arg1, &arg2, &arg3) == FAILURE) { @@ -663,15 +665,12 @@ switch (Z_LVAL_PP(arg3)) { case PHP_SYSTEM_READ: case PHP_BINARY_READ: - read_function = (int (*)(int, void *, int)) read; + read_function = (read_function) read; break; } } - if ((tmpbuf = (char*)emalloc((Z_LVAL_PP(arg2)+1)*sizeof(char))) == NULL) { - php_error(E_WARNING, "couldn't allocate memory"); - RETURN_FALSE; - } + tmpbuf = emalloc(Z_LVAL_PP(arg2) + 1); #ifndef PHP_WIN32 retval = (*read_function)(php_sock->socket, tmpbuf, Z_LVAL_PP(arg2)); @@ -686,6 +685,7 @@ tmpbuf[retval] = '\0'; RETURN_STRING(tmpbuf, 1); + efree(tmpbuf); } /* }}} */

« previous php.cvs (#5900) next »