]> granicus.if.org Git - php/commitdiff
Finalize the closing process of persistent streams. The current
authorIlia Alshanetsky <iliaa@php.net>
Tue, 29 Jul 2003 18:26:34 +0000 (18:26 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 29 Jul 2003 18:26:34 +0000 (18:26 +0000)
behavior/API is as follows:

1) To close a persistent use php_stream_pclose(), it will close the stream
and remove it from the persistent list.

2) Inside PHP code only explicit fclose() will close persistent streams,
all other actions such as unset() or assigning a value to stream handle
will not.

3) Regular streams can still be closed by either fclose(), unset() or an
assignment of a value to the stream handler.

ext/dba/dba.c
ext/standard/file.c
main/php_streams.h
main/streams/streams.c

index d58a92dd8555b1381a648b4b52cc6af17f04d874..ed74bbbb7eee61130777f746130b442b704ce8d0 100644 (file)
@@ -321,10 +321,18 @@ static void dba_close(dba_info *info TSRMLS_DC)
                pefree(info->path, info->flags&DBA_PERSISTENT);
        }
        if (info->fp && info->fp!=info->lock.fp) {
-               php_stream_close(info->fp);
+               if(info->flags&DBA_PERSISTENT) {
+                       php_stream_pclose(info->fp);
+               } else {
+                       php_stream_close(info->fp);
+               }
        }
        if (info->lock.fp) {
-               php_stream_close(info->lock.fp);
+               if(info->flags&DBA_PERSISTENT) {
+                       php_stream_pclose(info->lock.fp);
+               } else {
+                       php_stream_close(info->lock.fp);
+               }
        }
        if (info->lock.name) {
                pefree(info->lock.name, info->flags&DBA_PERSISTENT);
index e99be2e0c63b3b1d9815e1e6286f8add256f6d33..6b5c9a30ba9d2733b99d9eebb5d8a81a9450fb0b 100644 (file)
@@ -763,7 +763,11 @@ PHPAPI PHP_FUNCTION(fclose)
        }
 
        php_stream_from_zval(stream, arg1);
-       zend_list_delete(stream->rsrc_id);
+       if (!stream->is_persistent) {
+               zend_list_delete(stream->rsrc_id);
+       } else {
+               php_stream_pclose(stream);
+       }
 
        RETURN_TRUE;
 }
index 510ebae2b46271af0e5b1d3066adc5bc30d9c948..69c75960176ab875eaa185256e61546f07dfe733 100755 (executable)
@@ -249,11 +249,14 @@ PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream *
 #define PHP_STREAM_FREE_RELEASE_STREAM         2 /* pefree(stream) */
 #define PHP_STREAM_FREE_PRESERVE_HANDLE                4 /* tell ops->close to not close it's underlying handle */
 #define PHP_STREAM_FREE_RSRC_DTOR                      8 /* called from the resource list dtor */
+#define PHP_STREAM_FREE_PERSISTENT                     16 /* manually freeing a persistent connection */
 #define PHP_STREAM_FREE_CLOSE                          (PHP_STREAM_FREE_CALL_DTOR | PHP_STREAM_FREE_RELEASE_STREAM)
 #define PHP_STREAM_FREE_CLOSE_CASTED           (PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_PRESERVE_HANDLE)
+#define PHP_STREAM_FREE_CLOSE_PERSISTENT       (PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_PERSISTENT)
 PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC);
 #define php_stream_free(stream, close_options) _php_stream_free((stream), (close_options) TSRMLS_CC)
 #define php_stream_close(stream)       _php_stream_free((stream), PHP_STREAM_FREE_CLOSE TSRMLS_CC)
+#define php_stream_pclose(stream)      _php_stream_free((stream), PHP_STREAM_FREE_CLOSE_PERSISTENT TSRMLS_CC)
 
 PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC);
 #define php_stream_rewind(stream)      _php_stream_seek((stream), 0L, SEEK_SET TSRMLS_CC)
index 4b948c0bc79b29451b5c2ae4259c70637219e4f6..6f580dc986c5cd707bda4d97c77c5b26009c178a 100755 (executable)
@@ -254,7 +254,7 @@ fprintf(stderr, "stream_alloc: %s:%p persistent=%s\n", ops->label, ret, persiste
 
 static int _php_stream_free_persistent(list_entry *le, void *pStream TSRMLS_DC)
 {
-       return (le->ptr == pStream && !((php_stream *)pStream)->in_free);
+       return le->ptr == pStream;
 }
 
 PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /* {{{ */
@@ -358,7 +358,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
                        stream->readbuf = NULL;
                }
 
-               if (stream->is_persistent) {
+               if (stream->is_persistent && (close_options & PHP_STREAM_FREE_PERSISTENT)) {
                        /* we don't work with *stream but need its value for comparison */
                        zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t) _php_stream_free_persistent, stream TSRMLS_CC);
                }