Re: cvs: php4 /ext/sockets php_sockets.h sockets.c

From: Date: Mon, 23 Oct 2000 05:19:43 +0000
Subject: Re: cvs: php4 /ext/sockets php_sockets.h sockets.c
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-2238@lists.php.net to get a copy of this message
Are you sure it's not best to call the wrapped function by a new name instead of adding an INI entry? Adding INI entries tend to cause PHP apps which run on one host not to run on another host. It's not great for portability and they are almost always overlooked. I don't know which version came first but the second one should just have a different name. Call it system_read or user_read or something like that depending on which one came second. Andi At 11:43 PM 10/22/00 +0000, Chris Vandomelen wrote:
chrisv          Sun Oct 22 16:43:48 2000 EDT
Modified files:
    /php4/ext/sockets   php_sockets.h sockets.c
Log: Added ini entry for choosing whether to use the read() wrapper or directly calling the read() system call. # Some people were commenting about "oddities" in the wrapper that I hadn't # noticed before, though I've used it in many places before now.. Index: php4/ext/sockets/php_sockets.h diff -u php4/ext/sockets/php_sockets.h:1.5 php4/ext/sockets/php_sockets.h:1.6 --- php4/ext/sockets/php_sockets.h:1.5 Thu Sep 7 05:32:47 2000
+++ php4/ext/sockets/php_sockets.h      Sun Oct 22 16:43:48 2000
@@ -19,7 +19,7 @@ #ifndef PHP_SOCKETS_H #define PHP_SOCKETS_H -/* $Id: php_sockets.h,v 1.5 2000/09/07 12:32:47 thies Exp $ */ +/* $Id: php_sockets.h,v 1.6 2000/10/22 23:43:48 chrisv Exp $ */ #if HAVE_SOCKETS @@ -82,6 +82,7 @@ typedef struct {
        int le_destroy;
        int le_iov;
+       int use_system_read;
} php_sockets_globals; Index: php4/ext/sockets/sockets.c diff -u php4/ext/sockets/sockets.c:1.18 php4/ext/sockets/sockets.c:1.19
--- php4/ext/sockets/sockets.c:1.18     Sun Oct 22 00:54:49 2000
+++ php4/ext/sockets/sockets.c Sun Oct 22 16:43:48 2000 @@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
*/ -/* $Id: sockets.c,v 1.18 2000/10/22 07:54:49 chrisv Exp $ */ +/* $Id: sockets.c,v 1.19 2000/10/22 23:43:48 chrisv Exp $ */ #include "php.h" @@ -32,6 +32,7 @@ #include "ext/standard/info.h" #include "php_sockets.h" +#include "php_ini.h" #include <sys/types.h> #include <sys/socket.h> @@ -192,12 +193,18 @@
        }
} +PHP_INI_BEGIN()
+       STD_PHP_INI_BOOLEAN("sockets.use_system_read", "0", PHP_INI_ALL, OnUpdateInt, use_system_read, php_sockets_globals, sockets_globals)
+PHP_INI_END() + PHP_MINIT_FUNCTION(sockets) {
        SOCKETSLS_FETCH();
        SOCKETSG(le_destroy) = register_list_destructors(destroy_fd_sets, NULL, "sockets file descriptor set");
        SOCKETSG(le_iov)     = register_list_destructors(destroy_iovec,   NULL, "sockets i/o vector");
+       REGISTER_INI_ENTRIES();
+
        REGISTER_LONG_CONSTANT("AF_UNIX", AF_UNIX, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("AF_INET", AF_INET, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("SOCK_STREAM", SOCK_STREAM, CONST_CS | CONST_PERSISTENT);
@@ -619,12 +626,6 @@
      if (m & O_NONBLOCK)
           nonblock = 1;
-     {
-       char buf[255];
-       snprintf(buf, 255, "nonblock = %i\n", nonblock);
-       PUTS(buf);
-     }
-
      t = (char *) buf;
      while (keep_going) { /* (*t != '\n' && *t != '\r' && *t != '\0' && n < maxlen) { */
           m = read(fd, (void *) t, 1);
@@ -660,6 +661,8 @@
        zval **fd, **buf, **length, **binary;
        char *tmpbuf;
        int ret;
+       int (*read_function)(int, void *, int, int);
+       SOCKETSLS_FETCH();
        if (ZEND_NUM_ARGS() < 3 || ZEND_NUM_ARGS() > 4 ||
            zend_get_parameters_ex(ZEND_NUM_ARGS(), &fd, &buf, &length, &binary) == FAILURE) {
@@ -669,13 +672,19 @@
        v_convert_to_long_ex(ZEND_NUM_ARGS() - 1, fd, length, binary);
        convert_to_string_ex(buf);
+       if (SOCKETSG(use_system_read) == 1) {
+               read_function = (int (*)(int, void *, int, int)) read;
+       } else {
+               read_function = (int (*)(int, void *, int, int)) php_read;
+       }
+
        tmpbuf = emalloc(Z_LVAL_PP(length)*sizeof(char));
        if (tmpbuf == NULL) {
                php_error(E_WARNING, "Couldn't allocate memory from %s()", get_active_function_name());
                RETURN_FALSE;
        }
-       ret = php_read(Z_LVAL_PP(fd), tmpbuf, Z_LVAL_PP(length), ZEND_NUM_ARGS() == 4 ? Z_LVAL_PP(binary) : 0);
+       ret = (*read_function)(Z_LVAL_PP(fd), tmpbuf, Z_LVAL_PP(length), ZEND_NUM_ARGS() == 4 ? Z_LVAL_PP(binary) : 0);
        if (ret >= 0) {
                Z_STRVAL_PP(buf) = estrndup(tmpbuf,ret);
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-cvs-unsubscribe@lists.php.net For additional commands, e-mail: php-cvs-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
--- Andi Gutmans <andi@zend.com> http://www.zend.com/

« previous php.cvs (#2238) next »