CVS update: php3/functions

From: Date: Tue, 23 Mar 1999 12:22:17 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-4739@lists.php.net to get a copy of this message
Date: Tuesday March 23, 1999 @ 7:22 Author: ssb Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv20074 Modified Files: fsock.c Log Message: better buffer re-use Index: php3/functions/fsock.c diff -c php3/functions/fsock.c:1.90 php3/functions/fsock.c:1.91 *** php3/functions/fsock.c:1.90 Mon Mar 22 21:28:13 1999 --- php3/functions/fsock.c Tue Mar 23 07:22:17 1999 *************** *** 27,33 **** | Jim Winstead (jimw@php.net) | +----------------------------------------------------------------------+ */ ! /* $Id: fsock.c,v 1.90 1999/03/23 02:28:13 ssb Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif --- 27,33 ---- | Jim Winstead (jimw@php.net) | +----------------------------------------------------------------------+ */ ! /* $Id: fsock.c,v 1.91 1999/03/23 12:22:17 ssb Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif *************** *** 86,96 **** {NULL, NULL, NULL} }; static int php3_minit_fsock(INIT_FUNC_ARGS); static int php3_mshutdown_fsock(void); php3_module_entry fsock_module_entry = { ! "Socket functions", fsock_functions, php3_minit_fsock, php3_mshutdown_fsock, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES }; #ifndef THREAD_SAFE --- 86,108 ---- {NULL, NULL, NULL} }; + struct php3i_sockbuf { + int socket; + char *readbuf; + size_t readbuflen; + size_t readpos; + size_t writepos; + struct php3i_sockbuf *next; + }; + + static struct php3i_sockbuf *phpsockbuf = NULL; + static int php3_minit_fsock(INIT_FUNC_ARGS); static int php3_mshutdown_fsock(void); + static int php3_rshutdown_fsock(void); php3_module_entry fsock_module_entry = { ! "Socket functions", fsock_functions, php3_minit_fsock, php3_mshutdown_fsock, NULL, php3_rshutdown_fsock, NULL, STANDARD_MODULE_PROPERTIES }; #ifndef THREAD_SAFE *************** *** 98,104 **** static HashTable ht_socks; #endif ! /* {{{ lookup_hostname */ /* * Converts a host name to an IP address. --- 110,116 ---- static HashTable ht_socks; #endif ! /* {{{ lookup_hostname */ /* * Converts a host name to an IP address. *************** *** 118,124 **** return 0; } /* }}} */ ! /* {{{ _php3_is_persistent_sock */ int _php3_is_persistent_sock(int sock) { --- 130,136 ---- return 0; } /* }}} */ ! /* {{{ _php3_is_persistent_sock */ int _php3_is_persistent_sock(int sock) { *************** *** 131,137 **** return 0; } /* }}} */ ! /* {{{ _php3_fsockopen() */ /* This function takes an optional third argument which should be --- 143,149 ---- return 0; } /* }}} */ ! /* {{{ _php3_fsockopen() */ /* This function takes an optional third argument which should be *************** *** 270,276 **** _php3_fsockopen(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ - /* {{{ proto int pfsockopen(string hostname, int port [, int errno [, string errstr]]) Open persistent Internet or Unix domain socket connection */ PHP_FUNCTION(pfsockopen) --- 282,287 ---- *************** *** 279,299 **** } /* }}} */ ! struct php3i_sockbuf { ! int socket; ! char *readbuf; ! size_t readbuflen; ! size_t readpos; ! size_t writepos; ! struct php3i_sockbuf *next; ! }; ! ! static struct php3i_sockbuf *phpsockbuf = NULL; int _php3_sock_fgets(char *buf, int maxlen, int socket) { struct php3i_sockbuf *sockbuf = NULL, *tmpsockbuf; ! int bytesread, toread, len, buflen, count = 0, remove = 0; char *nl; tmpsockbuf = phpsockbuf; --- 290,301 ---- } /* }}} */ ! /* {{{ _php3_sock_fgets() */ int _php3_sock_fgets(char *buf, int maxlen, int socket) { struct php3i_sockbuf *sockbuf = NULL, *tmpsockbuf; ! int bytesread, toread, len, buflen, count = 0; char *nl; tmpsockbuf = phpsockbuf; *************** *** 317,327 **** sockbuf->readpos += toread; count += toread; buf += toread; ! /* if a newline was not found, or if the buffer has been ! * exhausted, the buffer may be unlinked ! */ ! if (nl == NULL || sockbuf->readpos >= sockbuf->writepos) { ! remove = 1; } if (nl != NULL) { /* if a newline was found, skip the recv() loop */ --- 319,326 ---- sockbuf->readpos += toread; count += toread; buf += toread; ! if (sockbuf->readpos >= sockbuf->writepos) { ! sockbuf->readpos = sockbuf->writepos = 0; } if (nl != NULL) { /* if a newline was found, skip the recv() loop */ *************** *** 369,399 **** } memcpy(sockbuf->readbuf + sockbuf->writepos, buf, buflen); sockbuf->writepos += buflen; - remove = 0; } sock_fgets_exit: - if (sockbuf && remove) { - struct php3i_sockbuf *prev = phpsockbuf; - - while (prev) { - if (prev->next == sockbuf) { - prev->next = sockbuf->next; - } - prev = prev->next; - } - efree(sockbuf->readbuf); - efree(sockbuf); - } *buf = '\0'; return count; } int _php3_sock_fread(char *buf, int maxlen, int socket) { struct php3i_sockbuf *sockbuf = phpsockbuf; ! int bytesread, toread, count = 0, remove = 0; while (sockbuf) { if (sockbuf->socket == socket) { --- 368,387 ---- } memcpy(sockbuf->readbuf + sockbuf->writepos, buf, buflen); sockbuf->writepos += buflen; } sock_fgets_exit: *buf = '\0'; return count; } + /* }}} */ + /* {{{ _php3_sock_fread() */ int _php3_sock_fread(char *buf, int maxlen, int socket) { struct php3i_sockbuf *sockbuf = phpsockbuf; ! int bytesread, toread, count = 0; while (sockbuf) { if (sockbuf->socket == socket) { *************** *** 424,429 **** --- 412,418 ---- return count; } + /* }}} */ /* {{{ module start/shutdown functions */ /* {{{ _php3_sock_destroy */ *************** *** 431,457 **** static void _php3_sock_destroy(void *data) { int *sock = (int *) data; - - #if 0 - if (phpsockbuf) { - struct php3i_sockbuf *buf = phpsockbuf, *prev = NULL; - - while (buf) { - if (buf->socket == *sock) { - if (prev) { - prev->next = buf->next; - } else { - phpsockbuf = buf->next; - } - efree(buf->readbuf); - efree(buf); - } - prev = buf; - buf = buf->next; - } - } - #endif - close(*sock); } #endif --- 420,425 ---- *************** *** 478,483 **** --- 446,468 ---- return SUCCESS; } /* }}} */ + /* {{{ php3_rshutdown_fsock() */ + + static int php3_rshutdown_fsock(void) + { + struct php3i_sockbuf *sockbuf = phpsockbuf, *this; + + while (sockbuf) { + this = sockbuf; + sockbuf = this->next; + efree(this->readbuf); + efree(this); + } + return SUCCESS; + } + + /* }}} */ + /* }}} */ /* -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#4739) next »