cvs: php-src /main/streams userspace.c

From: Date: Wed, 21 Jan 2004 10:17:14 +0000
Subject: cvs: php-src /main/streams userspace.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-25799@lists.php.net to get a copy of this message
hholzgra Wed Jan 21 05:17:14 2004 EDT Modified files: /php-src/main/streams userspace.c Log: stream_lock() method added to userspace streams wrapper http://cvs.php.net/diff.php/php-src/main/streams/userspace.c?r1=1.18&r2=1.19&ty=u Index: php-src/main/streams/userspace.c diff -u php-src/main/streams/userspace.c:1.18 php-src/main/streams/userspace.c:1.19 --- php-src/main/streams/userspace.c:1.18 Thu Jan 8 03:17:59 2004 +++ php-src/main/streams/userspace.c Wed Jan 21 05:17:12 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: userspace.c,v 1.18 2004/01/08 08:17:59 andi Exp $ */ +/* $Id: userspace.c,v 1.19 2004/01/21 10:17:12 hholzgra Exp $ */ #include "php.h" #include "php_globals.h" @@ -110,6 +110,7 @@ #define USERSTREAM_DIR_READ "dir_readdir" #define USERSTREAM_DIR_REWIND "dir_rewinddir" #define USERSTREAM_DIR_CLOSE "dir_closedir" +#define USERSTREAM_LOCK "stream_lock" /* {{{ class should have methods like these: @@ -759,6 +760,55 @@ return ret; } + +static int php_userstreamop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) { + zval func_name; + zval *retval = NULL; + int call_result; + php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; + int ret = -1; + zval *zvalue; + zval **args[1]; + + MAKE_STD_ZVAL(zvalue); + ZVAL_LONG(zvalue, value); + args[0] = &zvalue; + + switch (option) { + case PHP_STREAM_OPTION_LOCKING: + // TODO wouldblock + ZVAL_STRINGL(&func_name, USERSTREAM_LOCK, sizeof(USERSTREAM_LOCK)-1, 0); + + call_result = call_user_function_ex(NULL, + &us->object, + &func_name, + &retval, + 1, args, 0, NULL TSRMLS_CC); + + if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_BOOL) { + ret = !Z_LVAL_P(retval); + } else if (call_result == FAILURE) { + if (value == 0) { + ret = 0; // lock support test (TODO: more check) + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_LOCK " is not implemented!", + us->wrapper->classname); + } + } + + if (retval) + zval_ptr_dtor(&retval); + + break; + } + + /* clean up */ + zval_ptr_dtor(&zvalue); + + return ret; +} + + static int user_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; @@ -1152,6 +1202,7 @@ { zval func_name; zval *retval = NULL; + zval **args[1]; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1, 0); @@ -1175,8 +1226,8 @@ "user-space", php_userstreamop_seek, NULL, /* cast */ - php_userstreamop_stat, /* stat */ - NULL /* set_option */ + php_userstreamop_stat, + php_userstreamop_set_option, }; php_stream_ops php_stream_userspace_dir_ops = {

« previous php.cvs (#25799) next »