CVS update: php3/functions

From: Date: Thu, 20 May 1999 17:40:43 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-5815@lists.php.net to get a copy of this message
Date: Thursday May 20, 1999 @ 13:40 Author: sas Update of /repository/php3/functions In directory php:/tmp/cvs-serv12552/functions Modified Files: fsock.c fsock.h Log Message: - improved memory allocation strategy - limit maximum number of pre-reads Index: php3/functions/fsock.c diff -u php3/functions/fsock.c:1.96 php3/functions/fsock.c:1.97 --- php3/functions/fsock.c:1.96 Thu May 20 13:01:37 1999 +++ php3/functions/fsock.c Thu May 20 13:40:43 1999 @@ -27,7 +27,7 @@ | Jim Winstead (jimw@php.net) | +----------------------------------------------------------------------+ */ -/* $Id: fsock.c,v 1.96 1999/05/20 17:01:37 sas Exp $ */ +/* $Id: fsock.c,v 1.97 1999/05/20 17:40:43 sas Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif @@ -195,7 +195,7 @@ if (persistent && _php3_hash_find(&ht_keys, key, strlen(key) + 1, (void *) &sockp) == SUCCESS) { - efree(key); + FREE_SOCK; *sock = *sockp; RETURN_LONG(php3_list_insert(sock, GLOBAL(wsa_fp))); } @@ -341,6 +341,7 @@ } #define CHUNK_SIZE 2048 +#define MAX_CHUNKS_PER_READ 10 /* this reads all available data on a socket */ size_t _php3_sock_read(php3i_sockbuf *sock) @@ -348,14 +349,17 @@ char buf[CHUNK_SIZE]; int nr_bytes; size_t nr_read = 0; + int i; if(sock->eof) return nr_read; - while(1) { + for(i = 0; i < MAX_CHUNKS_PER_READ; i++) { nr_bytes = recv(sock->socket, buf, CHUNK_SIZE, 0); if(nr_bytes > 0) { - sock->readbuflen += nr_bytes; - sock->readbuf = erealloc(sock->readbuf, sock->readbuflen); + if(sock->writepos + nr_bytes > sock->readbuflen) { + sock->readbuflen += CHUNK_SIZE; + sock->readbuf = erealloc(sock->readbuf, sock->readbuflen); + } memcpy(WRITEPTR(sock), buf, nr_bytes); sock->writepos += nr_bytes; nr_read += nr_bytes; @@ -376,10 +380,10 @@ if(!sock) sock = _php3_sock_create(socket); \ _php3_sock_read(sock) -int _php3_sock_fgets(char *buf, int maxlen, int socket) +size_t _php3_sock_fgets(char *buf, size_t maxlen, int socket) { char *p; - int ret = 0; + size_t ret = 0; size_t amount = 0; SOCK_FIND_AND_READ; @@ -426,9 +430,9 @@ return ret; } -int _php3_sock_fread(char *ptr, int size, int socket) +size_t _php3_sock_fread(char *ptr, size_t size, int socket) { - int ret = 0; + size_t ret = 0; SOCK_FIND_AND_READ; ret = MIN(TOREAD(sock), size); Index: php3/functions/fsock.h diff -u php3/functions/fsock.h:1.17 php3/functions/fsock.h:1.18 --- php3/functions/fsock.h:1.17 Thu May 20 12:34:35 1999 +++ php3/functions/fsock.h Thu May 20 13:40:43 1999 @@ -27,7 +27,7 @@ | Jim Winstead (jimw@php.net) | +----------------------------------------------------------------------+ */ -/* $Id: fsock.h,v 1.17 1999/05/20 16:34:35 sas Exp $ */ +/* $Id: fsock.h,v 1.18 1999/05/20 17:40:43 sas Exp $ */ #ifndef _FSOCK_H #define _FSOCK_H @@ -35,11 +35,11 @@ extern php3_module_entry fsock_module_entry; #define fsock_module_ptr &fsock_module_entry -extern PHP_FUNCTION(fsockopen); -extern PHP_FUNCTION(pfsockopen); +PHP_FUNCTION(fsockopen); +PHP_FUNCTION(pfsockopen); int lookup_hostname(const char *addr, struct in_addr *in); -int _php3_sock_fgets(char *buf, int maxlen, int socket); -int _php3_sock_fread(char *buf, int maxlen, int socket); +size_t _php3_sock_fgets(char *buf, size_t maxlen, int socket); +size_t _php3_sock_fread(char *buf, size_t maxlen, int socket); int _php3_sock_feof(int socket); int _php3_sock_fgetc(int socket); int _php3_is_persistent_sock(int); -- 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 (#5815) next »