]> granicus.if.org Git - php/commitdiff
Fix a bug in the persistent socket liveness checks and feof(); they were
authorWez Furlong <wez@php.net>
Wed, 4 Feb 2004 22:46:44 +0000 (22:46 +0000)
committerWez Furlong <wez@php.net>
Wed, 4 Feb 2004 22:46:44 +0000 (22:46 +0000)
using the default socket timeout of 60 seconds before returning the socket
to the calling script.  The reason they were using that value is that the
same code is used for feof(), so the fix is allowing the caller to
indicate the timeout value for liveness checks.

A possible remaining issue now is that 0 second timeout[1] for pfsockopen
is possibly too short; it's impossible to specify a sane value for all
possible uses, so maybe we need a stream context or an .ini option to
control this, or maybe use the timeout value that was passed to
pfsockopen().

# [1] by timeout, I mean the time that PHP will wait for data on a
# persistent socket before deciding if a new connection should be made;
# NOT the timeout while waiting for a new connection to be established.

main/streams/streams.c
main/streams/transports.c
main/streams/xp_socket.c

index dc7a4f37ed7fc0875d698461906c641746ecf0d0..e3fe39d9c0d3096dcc084182076da5b7b2221da9 100755 (executable)
@@ -602,9 +602,10 @@ PHPAPI int _php_stream_eof(php_stream *stream TSRMLS_DC)
                return 0;
        }
 
+       /* use the configured timeout when checking eof */
        if (!stream->eof && PHP_STREAM_OPTION_RETURN_ERR ==
                        php_stream_set_option(stream, PHP_STREAM_OPTION_CHECK_LIVENESS,
-                       0, NULL)) {
+                       -1, NULL)) {
                stream->eof = 1;
        }
 
index 1c20026655e29e732987c90a293748a67e2ff996..04a4eccfbd3baefdc02b65cadcaef22804e0c616 100644 (file)
@@ -74,6 +74,8 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int
        if (persistent_id) {
                switch(php_stream_from_persistent_id(persistent_id, &stream TSRMLS_CC)) {
                        case PHP_STREAM_PERSISTENT_SUCCESS:
+                               /* use a 0 second timeout when checking if the socket
+                                * has already died */
                                if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_CHECK_LIVENESS, 0, NULL)) {
                                        return stream;
                                }
index 00b20b2b6338eae57bcbac5aa61f8ff4cfee4130..d70a9c79bad6062c863bb02d2ddffc03621ce453 100644 (file)
@@ -230,10 +230,14 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void
                                char buf;
                                int alive = 1;
 
-                               if (sock->timeout.tv_sec == -1) {
-                                       tv.tv_sec = FG(default_socket_timeout);
+                               if (value == -1) {
+                                       if (sock->timeout.tv_sec == -1) {
+                                               tv.tv_sec = FG(default_socket_timeout);
+                                       } else {
+                                               tv = sock->timeout;
+                                       }
                                } else {
-                                       tv = sock->timeout;
+                                       tv.tv_sec = value;
                                }
 
                                if (sock->socket == -1) {