diff options
author | Max Kellermann <max@duempel.org> | 2009-12-31 10:02:55 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-12-31 18:27:35 +0100 |
commit | aad05fd1386442330ecc0a15b86cf8081ea47c83 (patch) | |
tree | 66e9063f50b1c78cb8dda928e511f84f02f95891 /src/archive/zzip_archive_plugin.c | |
parent | 032c5376ad0ad8dca135d210363ef8e454e11167 (diff) | |
download | mpd-aad05fd1386442330ecc0a15b86cf8081ea47c83.tar.gz mpd-aad05fd1386442330ecc0a15b86cf8081ea47c83.tar.xz mpd-aad05fd1386442330ecc0a15b86cf8081ea47c83.zip |
archive: use reference counting for archive+input
Make the input_stream implementation hold a reference on the
archive_file object. Allow the caller to "close" the archive_file
object immediately, no matter if the open_stream() method has
succeeded or not.
Diffstat (limited to 'src/archive/zzip_archive_plugin.c')
-rw-r--r-- | src/archive/zzip_archive_plugin.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/archive/zzip_archive_plugin.c b/src/archive/zzip_archive_plugin.c index fb7af74ed..755baff74 100644 --- a/src/archive/zzip_archive_plugin.c +++ b/src/archive/zzip_archive_plugin.c @@ -26,6 +26,7 @@ #include "archive_api.h" #include "archive_api.h" #include "input_plugin.h" +#include "refcount.h" #include <zzip/zzip.h> #include <glib.h> @@ -34,6 +35,8 @@ struct zzip_archive { struct archive_file base; + struct refcount ref; + ZZIP_DIR *dir; GSList *list; GSList *iter; @@ -56,6 +59,7 @@ zzip_archive_open(const char *pathname, GError **error_r) ZZIP_DIRENT dirent; archive_file_init(&context->base, &zzip_archive_plugin); + refcount_init(&context->ref); // open archive context->list = NULL; @@ -102,6 +106,10 @@ static void zzip_archive_close(struct archive_file *file) { struct zzip_archive *context = (struct zzip_archive *) file; + + if (!refcount_dec(&context->ref)) + return; + if (context->list) { //free list for (GSList *tmp = context->list; tmp != NULL; tmp = g_slist_next(tmp)) @@ -151,6 +159,9 @@ zzip_archive_open_stream(struct archive_file *file, struct input_stream *is, zzip_file_stat(zis->file, &z_stat); is->size = z_stat.st_size; + + refcount_inc(&context->ref); + return true; } |