cvs: /php3/functions fsock.c
| From: | sas | Date: | Tue, 13 Jul 1999 12:33:38 +0000 |
| Subject: | cvs: /php3/functions fsock.c | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-8444@lists.php.net to get a copy of this message | ||
sas Tue Jul 13 12:33:38 1999 EDT
Modified files:
/php3/functions fsock.c
Log:
I convinced myself that this more complex form is necessary
to avoid staling on blocking sockets, since we don't _need_
to read maxlen.
This is real-world tested, so everybody should be happy with
this code now.
Index: php3/functions/fsock.c
diff -u php3/functions/fsock.c:1.130 php3/functions/fsock.c:1.131
--- php3/functions/fsock.c:1.130 Sat Jul 10 21:28:47 1999
+++ php3/functions/fsock.c Tue Jul 13 12:33:37 1999
@@ -27,7 +27,7 @@
| Jim Winstead (jimw@php.net) |
+----------------------------------------------------------------------+
*/
-/* $Id: fsock.c,v 1.130 1999/07/11 01:28:47 sas Exp $ */
+/* $Id: fsock.c,v 1.131 1999/07/13 16:33:37 sas Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
@@ -594,14 +594,31 @@
* FIXME: fgets depends on '\n' as line delimiter
*/
+#define SEARCHCR \
+ p = memchr(READPTR(sock), '\n', MIN(TOREAD(sock), maxlen - 1));
+
char *_php3_sock_fgets(char *buf, size_t maxlen, int socket)
{
char *p = NULL;
char *ret = NULL;
size_t amount = 0;
- SOCK_FIND_AND_READ_MAX(maxlen);
-
- p = memchr(READPTR(sock), '\n', MIN(TOREAD(sock), maxlen - 1));
+ size_t nr_read;
+ SOCK_FIND(sock, socket);
+
+ SEARCHCR;
+
+ if(!p) {
+ if(sock->is_blocked) {
+ for(nr_read = 0; !p && !sock->eof && nr_read < maxlen; ) {
+ nr_read += _php3_sock_read_internal(sock);
+ SEARCHCR;
+ }
+ } else {
+ _php3_sock_read(sock);
+ SEARCHCR;
+ }
+ }
+
if(p) {
amount = (ptrdiff_t) p - (ptrdiff_t) READPTR(sock) + 1;