cvs commit
| From: | sas | Date: | Sat, 10 Jul 1999 13:04:00 +0000 |
| Subject: | cvs commit | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-8271@lists.php.net to get a copy of this message | ||
From: sas
Date: Sat Jul 10 13:04:00 1999
Modified files:
php3/functions/fsock.c
Log message:
improve fgets and generally blocking sockets -
should fix the observed problems
Index: php3/functions/fsock.c
diff -u php3/functions/fsock.c:1.123 php3/functions/fsock.c:1.124
--- php3/functions/fsock.c:1.123 Sun Jun 20 06:28:06 1999
+++ php3/functions/fsock.c Sat Jul 10 13:04:00 1999
@@ -27,7 +27,7 @@
| Jim Winstead (jimw@php.net) |
+----------------------------------------------------------------------+
*/
-/* $Id: fsock.c,v 1.123 1999/06/20 10:28:06 sas Exp $ */
+/* $Id: fsock.c,v 1.124 1999/07/10 17:04:00 sas Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
@@ -380,7 +380,7 @@
}
/* }}} */
-#define CHUNK_SIZE 2048
+#define CHUNK_SIZE 8192
#define SOCK_DESTROY(sock) \
if(sock->readbuf) pefree(sock->readbuf, sock->persistent); \
if(sock->prev) sock->prev->next = sock->next; \
@@ -506,19 +506,12 @@
}
}
-static size_t _php3_sock_read_limited(php3i_sockbuf *sock, int maxread)
+static size_t _php3_sock_read_internal(php3i_sockbuf *sock)
{
char buf[CHUNK_SIZE];
int nr_bytes;
size_t nr_read = 0;
- /* we want to avoid system calls - therefore we check,
- whether we already have enough data in the buffer
- or if eof is already set */
-
- if(sock->eof || TOREAD(sock) >= maxread)
- return 0;
-
/* For blocking sockets, we wait until there is some
data to read (real data or EOF)
@@ -526,10 +519,11 @@
therefore sock->eof would be set errornously.
*/
+
if(sock->is_blocked) {
_php3_sock_wait_for_data(sock);
}
-
+
/* read at a maximum sock->chunk_size */
nr_bytes = recv(sock->socket, buf, sock->chunk_size, 0);
if(nr_bytes > 0) {
@@ -548,6 +542,13 @@
return nr_read;
}
+static void _php3_sock_read_total(php3i_sockbuf *sock, size_t maxread)
+{
+ while(!sock->eof && TOREAD(sock) < maxread) {
+ _php3_sock_read_internal(sock);
+ }
+}
+
static size_t _php3_sock_read(php3i_sockbuf *sock)
{
size_t nr_bytes;
@@ -555,7 +556,7 @@
int i;
for(i = 0; !sock->eof && i < MAX_CHUNKS_PER_READ; i++) {
- nr_bytes = _php3_sock_read_limited(sock, CHUNK_SIZE);
+ nr_bytes = _php3_sock_read_internal(sock);
if(nr_bytes == 0) break;
nr_read += nr_bytes;
}
@@ -577,10 +578,10 @@
#define SOCK_FIND_AND_READ_MAX(max) \
SOCK_FIND(sock, socket); \
- if(sock->is_blocked) _php3_sock_read_limited(sock, max); else _php3_sock_read(sock)
+ if(sock->is_blocked) _php3_sock_read_total(sock, max); else _php3_sock_read(sock)
/*
- * FIXME: fgets depends on '\n' as line delimiters
+ * FIXME: fgets depends on '\n' as line delimiter
*/
char *_php3_sock_fgets(char *buf, size_t maxlen, int socket)
@@ -588,30 +589,16 @@
char *p = NULL;
char *ret = NULL;
size_t amount = 0;
- size_t nr_read;
- size_t nr_toread;
- SOCK_FIND(sock, socket);
-
- if(maxlen < 0) return ret;
+ SOCK_FIND_AND_READ_MAX(maxlen);
- if(sock->is_blocked) {
- nr_toread = 0;
- for(nr_read = 1; !sock->eof && nr_read < maxlen; ) {
- nr_read += _php3_sock_read_limited(sock, nr_toread);
- if((p = memchr(READPTR(sock), '\n', TOREAD(sock))) != NULL) break;
- nr_toread = 512;
- }
- } else {
- _php3_sock_read(sock);
- p = memchr(READPTR(sock), '\n', MIN(TOREAD(sock), maxlen - 1));
- }
+ p = memchr(READPTR(sock), '\n', MIN(TOREAD(sock), maxlen - 1));
if(p) {
amount = (ptrdiff_t) p - (ptrdiff_t) READPTR(sock) + 1;
} else {
amount = TOREAD(sock);
}
-
+
amount = MIN(amount, maxlen - 1);
if(amount > 0) {