cvs: php4 /ext/sockets sockets.c
| From: | Chris Vandomelen | Date: | Fri, 15 Sep 2000 23:44:30 +0000 |
| Subject: | cvs: php4 /ext/sockets sockets.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1765@lists.php.net to get a copy of this message | ||
chrisv Fri Sep 15 16:44:30 2000 EDT
Modified files:
/php4/ext/sockets sockets.c
Log:
Changed assignment in read() to be more sane.
Index: php4/ext/sockets/sockets.c
diff -u php4/ext/sockets/sockets.c:1.13 php4/ext/sockets/sockets.c:1.14
--- php4/ext/sockets/sockets.c:1.13 Thu Sep 14 14:48:15 2000
+++ php4/ext/sockets/sockets.c Fri Sep 15 16:44:30 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: sockets.c,v 1.13 2000/09/14 21:48:15 chrisv Exp $ */
+/* $Id: sockets.c,v 1.14 2000/09/15 23:44:30 chrisv Exp $ */
#include "php.h"
@@ -580,6 +580,37 @@
/* {{{ proto int read(int fd, string &buf, int length)
Reads length bytes from fd into buf */
+
+/* php_read -- wrapper around read() so that it only reads to a \r, \n, or \0. */
+
+int php_read(int fd, void *buf, int maxlen)
+{
+ char *t;
+ int m = 0, n = 0;
+ int no_read = 0;
+
+ errno = 0;
+ t = (char *) buf;
+ while (*t != '\n' && *t != '\r' && *t != '\0'
&& n < maxlen) {
+ if (m > 0) {
+ t++;
+ n++;
+ } else if (m == 0) {
+ no_read++;
+ if (no_read > 200) {
+ errno = ECONNRESET;
+ return -1;
+ }
+ }
+ m = read(fd, (void *) t, 1);
+ if (errno != 0 && errno != ESPIPE && errno != EAGAIN) {
+ return -1;
+ }
+ errno = 0;
+ }
+ return n;
+}
+
PHP_FUNCTION(read)
{
zval **fd, **buf, **length;
@@ -599,10 +630,10 @@
RETURN_FALSE;
}
- ret = read(Z_LVAL_PP(fd), tmpbuf, Z_LVAL_PP(length));
+ ret = php_read(Z_LVAL_PP(fd), tmpbuf, Z_LVAL_PP(length));
if (ret >= 0) {
- Z_STRVAL_PP(buf) = estrndup(tmpbuf,strlen(tmpbuf));
+ Z_STRVAL_PP(buf) = estrndup(tmpbuf,ret);
Z_STRLEN_PP(buf) = ret;
efree(tmpbuf);