From 27fc61c4dc81f422cb9b72e4d144213ef6ba8d3c Mon Sep 17 00:00:00 2001 From: Sascha Schumann Date: Thu, 20 May 1999 13:56:19 +0000 Subject: [PATCH] Apply the fix for feof() --- ext/standard/file.c | 3 +-- ext/standard/fsock.c | 44 +++++++++++++++++++++++++++++++++----------- ext/standard/fsock.h | 1 + 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/ext/standard/file.c b/ext/standard/file.c index 84f902d91df..399804bb82c 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -703,7 +703,6 @@ PHP_FUNCTION(feof) int id, type; int issock=0; int socketd=0, *sock; - unsigned int temp; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; @@ -721,7 +720,7 @@ PHP_FUNCTION(feof) /* we're at the eof if the file doesn't exist */ RETURN_TRUE; } - if ((issock?!(recv(socketd,(char *)&temp,1,MSG_PEEK)):feof(fp))) { + if ((issock?(_php3_sock_eof(socketd)):feof(fp))) { RETURN_TRUE; } else { RETURN_FALSE; diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c index 1c161468ef7..29bb65ff660 100644 --- a/ext/standard/fsock.c +++ b/ext/standard/fsock.c @@ -93,6 +93,8 @@ struct php3i_sockbuf { static struct php3i_sockbuf *phpsockbuf; +typedef struct php3i_sockbuf php3i_sockbuf; + static int php3_minit_fsock(INIT_FUNC_ARGS); static int php3_mshutdown_fsock(SHUTDOWN_FUNC_ARGS); static int php3_rshutdown_fsock(SHUTDOWN_FUNC_ARGS); @@ -290,23 +292,43 @@ PHP_FUNCTION(pfsockopen) * (buffered data is not persistent) * - php3_fopen_url_wrapper() is still doing single-byte lookahead/read */ -/* {{{ _php3_sock_fgets() */ -int _php3_sock_fgets(char *buf, int maxlen, int socket) +static php3i_sockbuf *_php3_sock_findsock(int socket) { - struct php3i_sockbuf *sockbuf = NULL, *tmpsockbuf; - int bytesread, toread, len, buflen, count = 0; - char *nl; + /* FIXME: O(n) could be improved */ - tmpsockbuf = phpsockbuf; - while (tmpsockbuf) { - if (tmpsockbuf->socket == socket) { - sockbuf = tmpsockbuf; + php3i_sockbuf *buf = NULL, *tmp; + + for(tmp = phpsockbuf; tmp; tmp = tmp->next) + if(tmp->socket == socket) { + buf = tmp; break; } - tmpsockbuf = tmpsockbuf->next; - } + return buf; +} + +int _php3_sock_eof(int socket) +{ + php3i_sockbuf *sockbuf; + int ret = 0; + + sockbuf = _php3_sock_findsock(socket); + if(sockbuf) { + ret = (sockbuf->writepos - sockbuf->readpos) == 0 ? 1 : 0; + } + return ret; +} + +/* {{{ _php3_sock_fgets() */ +int _php3_sock_fgets(char *buf, int maxlen, int socket) +{ + struct php3i_sockbuf *sockbuf; + int bytesread, toread, len, buflen, count = 0; + char *nl; + + sockbuf = _php3_sock_findsock(socket); + if (sockbuf) { toread = sockbuf->writepos - sockbuf->readpos; if (toread > maxlen) { diff --git a/ext/standard/fsock.h b/ext/standard/fsock.h index fbd15c9948d..a4a01b1bf90 100644 --- a/ext/standard/fsock.h +++ b/ext/standard/fsock.h @@ -53,6 +53,7 @@ extern int lookup_hostname(const char *addr, struct in_addr *in); extern int _php3_sock_fgets(char *buf, int maxlen, int socket); extern int _php3_sock_fread(char *buf, int maxlen, int socket); extern int _php3_is_persistent_sock(int); +int _php3_sock_eof(int socket); #define phpext_fsock_ptr fsock_module_ptr