add uv_guess_handle

This commit is contained in:
Shuhei Tanuma 2012-07-16 02:06:05 +09:00
parent ccd0c57305
commit c919487ebe
2 changed files with 39 additions and 1 deletions

View File

@ -2019,12 +2019,16 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_is_writable, 0, 0, 1)
ZEND_ARG_INFO(0, handle)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_walk, 0, 0, 1)
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_walk, 0, 0, 3)
ZEND_ARG_INFO(0, loop)
ZEND_ARG_INFO(0, callback)
ZEND_ARG_INFO(0, opaque)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_guess_handle, 0, 0, 1)
ZEND_ARG_INFO(0, fd)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_ref, 0, 0, 1)
ZEND_ARG_INFO(0, loop)
ZEND_END_ARG_INFO()
@ -4075,6 +4079,31 @@ PHP_FUNCTION(uv_walk)
}
/* }}} */
/* {{{ proto long uv_guess_handle(resource $uv)
*/
PHP_FUNCTION(uv_guess_handle)
{
zval *handle;
php_uv_t *uv = NULL;
long fd = -1;
uv_handle_type type;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"z",&handle) == FAILURE) {
return;
}
fd = php_uv_zval_to_fd(handle TSRMLS_CC);
if (fd < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid variable passed. can't convert to fd.");
return;
}
type = uv_guess_handle(fd);
RETURN_LONG(type);
}
/* }}} */
/* {{{ proto resource uv_pipe_init(resource $loop, long $ipc)
*/
PHP_FUNCTION(uv_pipe_init)
@ -6847,6 +6876,7 @@ static zend_function_entry uv_functions[] = {
PHP_FE(uv_is_readable, arginfo_uv_is_readable)
PHP_FE(uv_is_writable, arginfo_uv_is_writable)
PHP_FE(uv_walk, arginfo_uv_walk)
PHP_FE(uv_guess_handle, arginfo_uv_guess_handle)
/* idle */
PHP_FE(uv_idle_init, arginfo_uv_idle_init)
PHP_FE(uv_idle_start, arginfo_uv_idle_start)

8
uv.c
View File

@ -73,6 +73,14 @@ static int php_uv_class_init(TSRMLS_D)
zend_declare_class_constant_long(uv_class_entry, "HTTP_REQUEST", sizeof("HTTP_REQUEST")-1, HTTP_REQUEST TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "HTTP_RESPONSE", sizeof("HTTP_RESPONSE")-1, HTTP_RESPONSE TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "UNKNOWN_HANDLE", sizeof("UNKNOWN_HANDLE")-1, UV_UNKNOWN_HANDLE TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "ARES_TASK", sizeof("ARES_TASK")-1, UV_ARES_TASK TSRMLS_CC);
zend_declare_class_constant_long(uv_class_entry, "FILE", sizeof("FILE")-1, UV_FILE TSRMLS_CC);
#define XX(uc, lc) zend_declare_class_constant_long(uv_class_entry, #uc, sizeof(#uc)-1, UV_##uc TSRMLS_CC);
UV_HANDLE_TYPE_MAP(XX)
#undef XX
zend_declare_class_constant_long(uv_class_entry, "HANDLE_TYPE_MAX", sizeof("HANDLE_TYPE_MAX")-1, UV_HANDLE_TYPE_MAX TSRMLS_CC);
return 0;
}