summaryrefslogtreecommitdiff
path: root/main/network.c
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2002-03-19 03:49:03 +0000
committerWez Furlong <wez@php.net>2002-03-19 03:49:03 +0000
commit67231e25e44301a8a4509db96f34cf7f56cd5f52 (patch)
tree12ab5cd3651fec0885bb59c31875e0a67b52db3a /main/network.c
parenta85ea38eac29f3f00d12cdf525ac271f06e2e3ed (diff)
downloadphp-git-67231e25e44301a8a4509db96f34cf7f56cd5f52.tar.gz
make feof more useful on network streams
Diffstat (limited to 'main/network.c')
-rw-r--r--main/network.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/main/network.c b/main/network.c
index 25284a8eb8..0d80527018 100644
--- a/main/network.c
+++ b/main/network.c
@@ -45,6 +45,9 @@
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
+#if HAVE_SYS_POLL_H
+#include <sys/poll.h>
+#endif
#ifndef PHP_WIN32
#include <netinet/in.h>
@@ -677,13 +680,48 @@ static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS
php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
size_t ret = 0;
- if (sock->is_blocked) {
+ if (buf == NULL && count == 0) {
+ /* check for EOF condition */
+
+ if (sock->eof)
+ return EOF;
+
+ if (TOREAD(sock))
+ return 0;
+
+ /* no data in the buffer - lets examine the socket */
+#if HAVE_SYS_POLL_H
+ {
+ struct pollfd topoll;
+
+ topoll.fd = sock->socket;
+ topoll.events = POLLIN;
+ topoll.revents = 0;
+
+ if (poll(&topoll, 1, 0) == 1) {
+ return topoll.revents & POLLHUP ? EOF : 0;
+ }
+ }
+#endif
+
+ /* in the absence of other methods of checking if the
+ * socket is still active, try to read a chunk of data */
+ sock->timeout_event = 0;
+ php_sock_stream_read_internal(stream, sock TSRMLS_CC);
+
+ if (sock->timeout_event || sock->eof)
+ return EOF;
+
+ return 0;
+ }
+
+ if (sock->is_blocked) {
sock->timeout_event = 0;
while(!sock->eof && TOREAD(sock) < count && !sock->timeout_event)
php_sock_stream_read_internal(stream, sock TSRMLS_CC);
- }
- else
+ } else {
php_sock_stream_read(stream, sock TSRMLS_CC);
+ }
if(count < 0)
return ret;