use fci and fcc for read_cb

This commit is contained in:
Shuhei Tanuma 2012-07-11 21:52:12 +09:00
parent 10d2eadeff
commit 675d794060
2 changed files with 11 additions and 38 deletions

View File

@ -61,7 +61,6 @@
uv->in_free = 0;\
uv->address = NULL; \
uv->listen_cb = NULL; \
uv->read_cb = NULL; \
uv->read2_cb = NULL; \
uv->write_cb = NULL; \
uv->close_cb = NULL; \
@ -503,7 +502,7 @@ void static destruct_uv(zend_rsrc_list_entry *rsrc TSRMLS_DC)
obj->in_free = 1;
/* for now */
for (i = 0; i < 20; i++) {
for (i = 0; i < PHP_UV_CB_MAX; i++) {
php_uv_cb_t *cb = obj->callback[i];
if (cb != NULL) {
if (cb->fci.function_name != NULL) {
@ -523,11 +522,6 @@ void static destruct_uv(zend_rsrc_list_entry *rsrc TSRMLS_DC)
zval_ptr_dtor(&obj->address);
obj->address = NULL;
}
if (obj->read_cb) {
PHP_UV_DEBUG_PRINT("zval_ptr_dtor: read_cb\n");
zval_ptr_dtor(&obj->read_cb);
obj->read_cb = NULL;
}
if (obj->read2_cb) {
PHP_UV_DEBUG_PRINT("zval_ptr_dtor: read2_cb\n");
zval_ptr_dtor(&obj->read2_cb);
@ -671,7 +665,7 @@ static int php_uv_do_callback2(zval **retval_ptr, php_uv_t *uv, zval ***params,
if (ZEND_FCI_INITIALIZED(uv->callback[type]->fci)) {
uv->callback[type]->fci.params = params;
uv->callback[type]->fci.retval_ptr_ptr = retval_ptr;
uv->callback[type]->fci.param_count = 2;
uv->callback[type]->fci.param_count = param_count;
uv->callback[type]->fci.no_separation = 0;
if (zend_call_function(&uv->callback[type]->fci, &uv->callback[type]->fcc TSRMLS_CC) != SUCCESS) {
@ -904,30 +898,6 @@ static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf)
PHP_UV_DEBUG_PRINT("uv_read_cb\n");
if (nread < 0) {
/* does this should be in user-land ? */
//uv_shutdown_t* req;
/* Error or EOF */
//assert(uv_last_error(uv_default_loop()).code == UV_EOF);
//if (buf.base) {
// efree(buf.base);
//}
//req = (uv_shutdown_t*) emalloc(sizeof *req);
//PHP_UV_DEBUG_PRINT("uv_read_cb: read close\n");
//uv_shutdown(req, (uv_handle_t *)handle, php_uv_shutdown_cb);
//return;
}
if (nread == 0) {
/* Everything OK, but nothing read. */
//efree(buf.base);
//return;
}
MAKE_STD_ZVAL(buffer);
if (nread > 0) {
ZVAL_STRINGL(buffer,buf.base,nread, 1);
@ -946,7 +916,7 @@ static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf)
params[1] = &err;
params[2] = &buffer;
php_uv_do_callback(&retval_ptr, uv->read_cb, params, 3 TSRMLS_CC);
php_uv_do_callback2(&retval_ptr, uv, params, 3, PHP_UV_READ_CB TSRMLS_CC);
zval_ptr_dtor(&buffer);
zval_ptr_dtor(&rsc);
@ -2840,22 +2810,24 @@ PHP_FUNCTION(uv_close)
*/
PHP_FUNCTION(uv_read_start)
{
zval *client, *callback;
zval *client;
php_uv_t *uv;
zend_fcall_info fci = empty_fcall_info;
zend_fcall_info_cache fcc = empty_fcall_info_cache;
php_uv_cb_t *cb;
int r;
PHP_UV_DEBUG_PRINT("uv_read_start\n");
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"rz",&client, &callback) == FAILURE) {
"rf!",&client, &fci, &fcc) == FAILURE) {
return;
}
ZEND_FETCH_RESOURCE(uv, php_uv_t *, &client, -1, PHP_UV_RESOURCE_NAME, uv_resource_handle);
Z_ADDREF_P(callback);
zend_list_addref(uv->resource_id);
uv->read_cb = callback;
if(uv->type == IS_UV_TCP) {
uv->uv.tcp.data = uv;
} else if(uv->type == IS_UV_PIPE) {
@ -2863,6 +2835,8 @@ PHP_FUNCTION(uv_read_start)
} else {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "this type does not support yet");
}
php_uv_cb_init(&cb, uv, &fci, &fcc, PHP_UV_READ_CB);
r = uv_read_start((uv_stream_t*)php_uv_get_current_stream(uv), php_uv_read_alloc, php_uv_read_cb);
if (r) {

View File

@ -123,7 +123,6 @@ typedef struct {
char *buffer;
zval *address;
zval *listen_cb;
zval *read_cb;
zval *read2_cb;
zval *write_cb;
zval *shutdown_cb;