]> granicus.if.org Git - php/commitdiff
Apply the fix for feof()
authorSascha Schumann <sas@php.net>
Thu, 20 May 1999 13:56:19 +0000 (13:56 +0000)
committerSascha Schumann <sas@php.net>
Thu, 20 May 1999 13:56:19 +0000 (13:56 +0000)
ext/standard/file.c
ext/standard/fsock.c
ext/standard/fsock.h

index 84f902d91df55b9511957138b382fd79ea0dbb71..399804bb82c7b8e27c85bbc91e81d4d1367ab4ce 100644 (file)
@@ -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;
index 1c161468ef7f5a636100a9c2a9e7f53826602e05..29bb65ff660afb18746b432e6c077ae45ea2a483 100644 (file)
@@ -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) {
index fbd15c9948d617e200a02ae3b163138e47896756..a4a01b1bf90f3292a6ab6e2936a64b6bcb79a6dd 100644 (file)
@@ -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