tcp: check types

This commit is contained in:
Shuhei Tanuma 2012-07-24 00:12:56 +09:00
parent 7ac60188e9
commit c134d2fba2

View File

@ -2413,14 +2413,28 @@ static void php_uv_socket_getname(int type, INTERNAL_FUNCTION_PARAMETERS)
}
ZEND_FETCH_RESOURCE(uv, php_uv_t*, &handle, -1, PHP_UV_RESOURCE_NAME, uv_resource_handle);
switch (type) {
case 1:
if (uv->type != IS_UV_TCP) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "passed resource doesn't initialize for uv_tcp");
RETURN_FALSE;
}
error = uv_tcp_getsockname(&uv->uv.tcp, (struct sockaddr*)&addr, &addr_len);
break;
case 2:
if (uv->type != IS_UV_TCP) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "passed resource doesn't initialize for uv_tcp");
RETURN_FALSE;
}
error = uv_tcp_getpeername(&uv->uv.tcp, (struct sockaddr*)&addr, &addr_len);
break;
case 3:
if (uv->type != IS_UV_UDP) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "passed resource doesn't initialize for uv_tcp");
RETURN_FALSE;
}
error = uv_udp_getsockname(&uv->uv.udp, (struct sockaddr*)&addr, &addr_len);
break;
default:
@ -5945,6 +5959,11 @@ PHP_FUNCTION(uv_tcp_simultaneous_accepts)
}
ZEND_FETCH_RESOURCE(uv, php_uv_t*, &handle, -1, PHP_UV_RESOURCE_NAME, uv_resource_handle);
if (uv->type != IS_UV_TCP) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "passed resource doesn't initialize for uv_tcp");
RETURN_FALSE;
}
error = uv_tcp_simultaneous_accepts(&uv->uv.tcp, enable);
RETURN_LONG(error);
}