From 52b91e2b44b383b5bea3f5ec3de2ec62927ada0b Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Tue, 17 Jul 2012 21:58:52 +0900 Subject: [PATCH] uv_ref and uv_unref supports uv_loop resource --- php_uv.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/php_uv.c b/php_uv.c index d5ee315..4c9c19e 100644 --- a/php_uv.c +++ b/php_uv.c @@ -2537,23 +2537,27 @@ uv_unref($tcp); ```` -##### *TODO* - -* support uv_loop_t - */ PHP_FUNCTION(uv_unref) { zval *handle = NULL; php_uv_t *uv; + uv_loop_t *loop; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&handle) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(uv, php_uv_t *, &handle, -1, PHP_UV_RESOURCE_NAME, uv_resource_handle); - uv_unref((uv_handle_t *)php_uv_get_current_stream(uv)); - zend_list_delete(uv->resource_id); + + if (ZEND_FETCH_RESOURCE_NO_RETURN(loop, uv_loop_t*, &handle, -1, NULL, uv_loop_handle)) { + uv_unref((uv_handle_t *)loop); + zend_list_delete(Z_RESVAL_P(handle)); + } else if (ZEND_FETCH_RESOURCE_NO_RETURN(uv, php_uv_t*, &handle, -1, NULL, uv_resource_handle)) { + uv_unref((uv_handle_t *)php_uv_get_current_stream(uv)); + zend_list_delete(uv->resource_id); + } else { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "passes unexpected resource."); + } } /* }}} */ @@ -2723,14 +2727,21 @@ PHP_FUNCTION(uv_ref) { zval *handle = NULL; php_uv_t *uv; + uv_loop_t *loop; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&handle) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(uv, php_uv_t *, &handle, -1, PHP_UV_RESOURCE_NAME, uv_resource_handle); - uv_ref((uv_handle_t *)php_uv_get_current_stream(uv)); - zend_list_addref(uv->resource_id); + if (ZEND_FETCH_RESOURCE_NO_RETURN(loop, uv_loop_t*, &handle, -1, NULL, uv_loop_handle)) { + uv_ref((uv_handle_t *)loop); + zend_list_delete(Z_RESVAL_P(handle)); + } else if (ZEND_FETCH_RESOURCE_NO_RETURN(uv, php_uv_t*, &handle, -1, NULL, uv_resource_handle)) { + uv_ref((uv_handle_t *)php_uv_get_current_stream(uv)); + zend_list_addref(uv->resource_id); + } else { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "passes unexpected resource."); + } } /* }}} */