]> granicus.if.org Git - php/commitdiff
Fix refcounting problem with contexts.
authorWez Furlong <wez@php.net>
Mon, 19 May 2003 23:27:49 +0000 (23:27 +0000)
committerWez Furlong <wez@php.net>
Mon, 19 May 2003 23:27:49 +0000 (23:27 +0000)
Also, potentially fix stream_set_timeout issues on SSL streams.

ext/standard/file.c
ext/standard/fsock.c
main/network.c
main/streams.c

index 66bc863005e243d3207bd10bc0eb4714049045b7..bcde4a0c6dd9c7d9b0f6aacfe5a3f5fc861b97a5 100644 (file)
@@ -1110,8 +1110,9 @@ PHP_NAMED_FUNCTION(php_if_fopen)
        }
 
        php_stream_to_zval(stream, return_value);
-
-       return;
+       if (zcontext) {
+               ZVAL_ADDREF(zcontext);
+       }
 }
 /* }}} */
 
index adb7d55cb9e4161e93995dca4f879d32ccd8f21f..9a5a821c8ea5f6a8cc48c053747bd60ce9c1e5e6 100644 (file)
@@ -279,7 +279,10 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent)
                }
                RETURN_FALSE;
        }
-               
+       
+       if (zcontext) {
+               ZVAL_ADDREF(zcontext);
+       }
        php_stream_to_zval(stream, return_value);
 }
 
index c0c9010d47923a727d8adb286ea1ca477b1a4b71..3c84f64ecfed405018013cac5ae0c5c346264bbf 100644 (file)
@@ -917,8 +917,9 @@ static size_t php_sockop_write(php_stream *stream, const char *buf, size_t count
                }
        }
        
-       if (didwrite > 0)
+       if (didwrite > 0) {
                php_stream_notify_progress_increment(stream->context, didwrite, 0);
+       }
 
        return didwrite;
 }
@@ -975,6 +976,13 @@ static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS
        if (sock->ssl_active) {
                int retry = 1;
 
+               if (sock->is_blocked && !SSL_pending(sock->ssl_handle)) {
+                       php_sock_stream_wait_for_data(stream, sock TSRMLS_CC);
+                       if (sock->timeout_event) {
+                               return 0;
+                       }
+               }
+
                do {
                        nr_bytes = SSL_read(sock->ssl_handle, buf, count);
 
@@ -994,8 +1002,9 @@ static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS
        {
                if (sock->is_blocked) {
                        php_sock_stream_wait_for_data(stream, sock TSRMLS_CC);
-                       if (sock->timeout_event)
+                       if (sock->timeout_event) {
                                return 0;
+                       }
                }
 
                nr_bytes = recv(sock->socket, buf, count, 0);
@@ -1005,8 +1014,9 @@ static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS
                }
        }
 
-       if (nr_bytes > 0)
+       if (nr_bytes > 0) {
                php_stream_notify_progress_increment(stream->context, nr_bytes, 0);
+       }
 
        return nr_bytes;
 }
@@ -1126,6 +1136,7 @@ int _php_network_is_stream_alive(php_stream *stream)
                        }
                }
        }
+
        return alive;
 }
 
index 585716bae6103f24a19c02283e151a54a1e40a0f..0cb591ecef61837fb9a67e2fefe7a7155b8fd0fb 100755 (executable)
@@ -125,6 +125,10 @@ fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream);
        
        stream->rsrc_id = FAILURE;
 
+       if (stream->context) {
+               stream->context = NULL;
+       }
+
        return 0;
 }