mirror of
https://github.com/danog/ext-uv.git
synced 2024-11-30 04:29:01 +01:00
prettify codes: use common macro
This commit is contained in:
parent
6198618233
commit
023a096a1e
66
php_uv.c
66
php_uv.c
@ -76,6 +76,12 @@
|
|||||||
uv->fs_event_cb = NULL; \
|
uv->fs_event_cb = NULL; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if PHP_UV_DEBUG>=1
|
||||||
|
#define PHP_UV_DEBUG_PRINT(format, ...) fprintf(stderr,format, __VA_ARGS__);
|
||||||
|
#else
|
||||||
|
#define PHP_UV_DEBUG_PRINT(format, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
extern void php_uv_init(TSRMLS_D);
|
extern void php_uv_init(TSRMLS_D);
|
||||||
extern zend_class_entry *uv_class_entry;
|
extern zend_class_entry *uv_class_entry;
|
||||||
|
|
||||||
@ -289,15 +295,9 @@ void static destruct_uv(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
|||||||
{
|
{
|
||||||
int base_id = -1;
|
int base_id = -1;
|
||||||
php_uv_t *obj = (php_uv_t *)rsrc->ptr;
|
php_uv_t *obj = (php_uv_t *)rsrc->ptr;
|
||||||
#if PHP_UV_DEBUG>=1
|
|
||||||
fprintf(stderr,"# will be free: (resource_id: %d)", obj->resource_id);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (obj->in_free) {
|
PHP_UV_DEBUG_PRINT("# will be free: (resource_id: %d)", obj->resource_id);
|
||||||
/* TODO: why other php_uv_t has already set this? */
|
|
||||||
//fprintf(stderr, "resource_id: %d is freeing", obj->resource_id);
|
|
||||||
//return;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj->in_free = 1;
|
obj->in_free = 1;
|
||||||
if (obj->address) {
|
if (obj->address) {
|
||||||
@ -511,9 +511,7 @@ static void php_uv_write_cb(uv_write_t* req, int status)
|
|||||||
php_uv_t *uv = (php_uv_t*)req->data;
|
php_uv_t *uv = (php_uv_t*)req->data;
|
||||||
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
||||||
|
|
||||||
#if PHP_UV_DEBUG>=1
|
PHP_UV_DEBUG_PRINT("uv_write_cb: status: %d\n", status);
|
||||||
fprintf(stderr,"status: %d\n", status);
|
|
||||||
#endif
|
|
||||||
MAKE_STD_ZVAL(stat);
|
MAKE_STD_ZVAL(stat);
|
||||||
ZVAL_LONG(stat, status);
|
ZVAL_LONG(stat, status);
|
||||||
|
|
||||||
@ -600,9 +598,8 @@ static void php_uv_close_cb2(uv_handle_t *handle)
|
|||||||
{
|
{
|
||||||
php_uv_t *uv = (php_uv_t*)handle->data;
|
php_uv_t *uv = (php_uv_t*)handle->data;
|
||||||
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
||||||
#if PHP_UV_DEBUG>=1
|
PHP_UV_DEBUG_PRINT("uv_close_cb2:\n");
|
||||||
fprintf(stderr,"closecb2");
|
|
||||||
#endif
|
|
||||||
zend_list_delete(uv->resource_id);
|
zend_list_delete(uv->resource_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,9 +618,7 @@ static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf)
|
|||||||
php_uv_t *uv = (php_uv_t*)handle->data;
|
php_uv_t *uv = (php_uv_t*)handle->data;
|
||||||
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
||||||
|
|
||||||
#if PHP_UV_DEBUG>=1
|
PHP_UV_DEBUG_PRINT("uv_read_cb\n");
|
||||||
fprintf(stderr,"read_cb");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
/* does this should be in user-land ? */
|
/* does this should be in user-land ? */
|
||||||
@ -637,9 +632,8 @@ static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//req = (uv_shutdown_t*) emalloc(sizeof *req);
|
//req = (uv_shutdown_t*) emalloc(sizeof *req);
|
||||||
#if PHP_UV_DEBUG>=1
|
PHP_UV_DEBUG_PRINT("uv_read_cb: read close\n");
|
||||||
fprintf(stderr,"read close");
|
|
||||||
#endif
|
|
||||||
uv_close((uv_handle_t *)handle, php_uv_close_cb2);
|
uv_close((uv_handle_t *)handle, php_uv_close_cb2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -691,9 +685,7 @@ static void php_uv_prepare_cb(uv_prepare_t* handle, int status)
|
|||||||
php_uv_t *uv = (php_uv_t*)handle->data;
|
php_uv_t *uv = (php_uv_t*)handle->data;
|
||||||
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
||||||
|
|
||||||
#if PHP_UV_DEBUG>=1
|
PHP_UV_DEBUG_PRINT("prepare_cb\n");
|
||||||
fprintf(stderr,"prepare_cb");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MAKE_STD_ZVAL(zstat);
|
MAKE_STD_ZVAL(zstat);
|
||||||
ZVAL_LONG(zstat, status);
|
ZVAL_LONG(zstat, status);
|
||||||
@ -725,9 +717,7 @@ static void php_uv_check_cb(uv_check_t* handle, int status)
|
|||||||
php_uv_t *uv = (php_uv_t*)handle->data;
|
php_uv_t *uv = (php_uv_t*)handle->data;
|
||||||
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
||||||
|
|
||||||
#if PHP_UV_DEBUG>=1
|
PHP_UV_DEBUG_PRINT("check_cb\n");
|
||||||
fprintf(stderr,"check_cb");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MAKE_STD_ZVAL(zstat);
|
MAKE_STD_ZVAL(zstat);
|
||||||
ZVAL_LONG(zstat, status);
|
ZVAL_LONG(zstat, status);
|
||||||
@ -760,9 +750,7 @@ static void php_uv_async_cb(uv_async_t* handle, int status)
|
|||||||
php_uv_t *uv = (php_uv_t*)handle->data;
|
php_uv_t *uv = (php_uv_t*)handle->data;
|
||||||
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
||||||
|
|
||||||
#if PHP_UV_DEBUG>=1
|
PHP_UV_DEBUG_PRINT("async_cb\n");
|
||||||
fprintf(stderr,"async_cb");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MAKE_STD_ZVAL(zstat);
|
MAKE_STD_ZVAL(zstat);
|
||||||
ZVAL_LONG(zstat, status);
|
ZVAL_LONG(zstat, status);
|
||||||
@ -795,9 +783,7 @@ static void php_uv_work_cb(uv_work_t* req)
|
|||||||
uv = (php_uv_t*)req->data;
|
uv = (php_uv_t*)req->data;
|
||||||
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
||||||
|
|
||||||
#if PHP_UV_DEBUG>=1
|
PHP_UV_DEBUG_PRINT("work_cb\n");
|
||||||
fprintf(stderr,"work_cb");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
php_uv_do_callback(&retval_ptr, uv->work_cb, NULL, 0 TSRMLS_CC);
|
php_uv_do_callback(&retval_ptr, uv->work_cb, NULL, 0 TSRMLS_CC);
|
||||||
zval_ptr_dtor(&retval_ptr);
|
zval_ptr_dtor(&retval_ptr);
|
||||||
@ -820,9 +806,7 @@ static void php_uv_after_work_cb(uv_work_t* req)
|
|||||||
php_uv_t *uv = (php_uv_t*)req->data;
|
php_uv_t *uv = (php_uv_t*)req->data;
|
||||||
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
||||||
|
|
||||||
#if PHP_UV_DEBUG>=1
|
PHP_UV_DEBUG_PRINT("after_work_cb\n");
|
||||||
fprintf(stderr,"after_work_cb");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
php_uv_do_callback(&retval_ptr, uv->after_work_cb, NULL, 0 TSRMLS_CC);
|
php_uv_do_callback(&retval_ptr, uv->after_work_cb, NULL, 0 TSRMLS_CC);
|
||||||
zval_ptr_dtor(&retval_ptr);
|
zval_ptr_dtor(&retval_ptr);
|
||||||
@ -846,9 +830,7 @@ static void php_uv_fs_cb(uv_fs_t* req)
|
|||||||
int argc = 2;
|
int argc = 2;
|
||||||
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
||||||
|
|
||||||
#if PHP_UV_DEBUG>=1
|
PHP_UV_DEBUG_PRINT("vc_cb\n");
|
||||||
fprintf(stderr,"fs_cb");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MAKE_STD_ZVAL(result);
|
MAKE_STD_ZVAL(result);
|
||||||
ZVAL_LONG(result, uv->uv.fs.result);
|
ZVAL_LONG(result, uv->uv.fs.result);
|
||||||
@ -987,9 +969,7 @@ static void php_uv_fs_event_cb(uv_fs_event_t* req, const char* filename, int eve
|
|||||||
zval *name,*ev,*stat;
|
zval *name,*ev,*stat;
|
||||||
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
TSRMLS_FETCH_FROM_CTX(uv->thread_ctx);
|
||||||
|
|
||||||
#if PHP_UV_DEBUG>=1
|
PHP_UV_DEBUG_PRINT("fs_event_cb: %s, %d\n", filename, status);
|
||||||
fprintf(stderr,"fs_event_cb:%s, %d\n", filename, status);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MAKE_STD_ZVAL(name);
|
MAKE_STD_ZVAL(name);
|
||||||
MAKE_STD_ZVAL(ev);
|
MAKE_STD_ZVAL(ev);
|
||||||
@ -2182,9 +2162,7 @@ PHP_FUNCTION(uv_read_start)
|
|||||||
php_uv_t *uv;
|
php_uv_t *uv;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
#if PHP_UV_DEBUG>=1
|
PHP_UV_DEBUG_PRINT("uv_read_start\n");
|
||||||
fprintf(stderr,"uv_read_start");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
|
||||||
"rz",&client, &callback) == FAILURE) {
|
"rz",&client, &callback) == FAILURE) {
|
||||||
|
32
php_uv.h
32
php_uv.h
@ -30,24 +30,24 @@ extern zend_module_entry uv_module_entry;
|
|||||||
extern zend_class_entry *uv_class_entry;
|
extern zend_class_entry *uv_class_entry;
|
||||||
|
|
||||||
enum php_uv_resource_type{
|
enum php_uv_resource_type{
|
||||||
IS_UV_TCP = 0,
|
IS_UV_TCP = 0,
|
||||||
IS_UV_UDP = 1,
|
IS_UV_UDP = 1,
|
||||||
IS_UV_PIPE = 2,
|
IS_UV_PIPE = 2,
|
||||||
IS_UV_IDLE = 3,
|
IS_UV_IDLE = 3,
|
||||||
IS_UV_TIMER = 4,
|
IS_UV_TIMER = 4,
|
||||||
IS_UV_ASYNC = 5,
|
IS_UV_ASYNC = 5,
|
||||||
IS_UV_LOOP = 6,
|
IS_UV_LOOP = 6,
|
||||||
IS_UV_HANDLE = 7,
|
IS_UV_HANDLE = 7,
|
||||||
IS_UV_STREAM = 8,
|
IS_UV_STREAM = 8,
|
||||||
IS_UV_ADDRINFO = 9,
|
IS_UV_ADDRINFO = 9,
|
||||||
IS_UV_PROCESS = 10,
|
IS_UV_PROCESS = 10,
|
||||||
IS_UV_PREPARE = 11,
|
IS_UV_PREPARE = 11,
|
||||||
IS_UV_CHECK = 12,
|
IS_UV_CHECK = 12,
|
||||||
IS_UV_WORK = 13,
|
IS_UV_WORK = 13,
|
||||||
IS_UV_FS = 14,
|
IS_UV_FS = 14,
|
||||||
IS_UV_FS_EVENT = 15,
|
IS_UV_FS_EVENT = 15,
|
||||||
IS_UV_TTY = 16,
|
IS_UV_TTY = 16,
|
||||||
IS_UV_MAX = 16
|
IS_UV_MAX = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user