-
Notifications
You must be signed in to change notification settings - Fork 8k
ext/sockets: socket_set_option switch from convert_to_long to zval_tr… #17135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
0e4eeda
45270c6
695861e
6c5f436
1a14443
e18fbb3
d6e64e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1811,6 +1811,7 @@ PHP_FUNCTION(socket_set_option) | |||||
HashTable *opt_ht; | ||||||
zval *l_onoff, *l_linger; | ||||||
zval *sec, *usec; | ||||||
bool failed; | ||||||
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ollz", &arg1, socket_ce, &level, &optname, &arg4) == FAILURE) { | ||||||
RETURN_THROWS(); | ||||||
|
@@ -1883,11 +1884,19 @@ PHP_FUNCTION(socket_set_option) | |||||
RETURN_THROWS(); | ||||||
} | ||||||
|
||||||
convert_to_long(l_onoff); | ||||||
convert_to_long(l_linger); | ||||||
zend_long zl_onoff = zval_try_get_long(l_onoff, &failed); | ||||||
|
||||||
if (failed) { | ||||||
zend_argument_type_error(4, "\"%s\" must be an int, %s given", l_onoff_key, zend_zval_value_name(l_onoff)); | ||||||
|
||||||
RETURN_THROWS(); | ||||||
} | ||||||
zend_long zl_linger = zval_try_get_long(l_linger, &failed); | ||||||
if (failed) { | ||||||
zend_argument_type_error(4, "\"%s\" must be an int, %s given", l_linger_key, zend_zval_value_name(l_linger)); | ||||||
|
||||||
RETURN_THROWS(); | ||||||
} | ||||||
|
||||||
lv.l_onoff = (unsigned short)Z_LVAL_P(l_onoff); | ||||||
lv.l_linger = (unsigned short)Z_LVAL_P(l_linger); | ||||||
lv.l_onoff = (unsigned short)zl_onoff; | ||||||
lv.l_linger = (unsigned short)zl_linger; | ||||||
|
||||||
|
||||||
optlen = sizeof(lv); | ||||||
opt_ptr = &lv; | ||||||
|
@@ -1898,6 +1907,7 @@ PHP_FUNCTION(socket_set_option) | |||||
case SO_SNDTIMEO: { | ||||||
const char sec_key[] = "sec"; | ||||||
const char usec_key[] = "usec"; | ||||||
bool failed; | ||||||
|
||||||
convert_to_array(arg4); | ||||||
|
||||||
opt_ht = Z_ARRVAL_P(arg4); | ||||||
|
@@ -1911,15 +1921,23 @@ PHP_FUNCTION(socket_set_option) | |||||
RETURN_THROWS(); | ||||||
} | ||||||
|
||||||
convert_to_long(sec); | ||||||
convert_to_long(usec); | ||||||
zend_long zsec = zval_try_get_long(sec, &failed); | ||||||
|
||||||
if (failed) { | ||||||
zend_argument_type_error(4, "\"%s\" must be an int, %s given", sec_key, zend_zval_value_name(sec)); | ||||||
|
||||||
RETURN_THROWS(); | ||||||
} | ||||||
zend_long zusec = zval_try_get_long(usec, &failed); | ||||||
if (failed) { | ||||||
zend_argument_type_error(4, "\"%s\" must be an int, %s given", usec_key, zend_zval_value_name(usec)); | ||||||
|
||||||
RETURN_THROWS(); | ||||||
} | ||||||
#ifndef PHP_WIN32 | ||||||
tv.tv_sec = Z_LVAL_P(sec); | ||||||
tv.tv_usec = Z_LVAL_P(usec); | ||||||
tv.tv_sec = zsec; | ||||||
tv.tv_usec = zusec; | ||||||
optlen = sizeof(tv); | ||||||
opt_ptr = &tv; | ||||||
#else | ||||||
timeout = Z_LVAL_P(sec) * 1000 + Z_LVAL_P(usec) / 1000; | ||||||
timeout = zsec * 1000 + zusec / 1000; | ||||||
|
||||||
optlen = sizeof(int); | ||||||
opt_ptr = &timeout; | ||||||
#endif | ||||||
|
@@ -1971,15 +1989,19 @@ PHP_FUNCTION(socket_set_option) | |||||
|
||||||
#ifdef SO_ATTACH_REUSEPORT_CBPF | ||||||
case SO_ATTACH_REUSEPORT_CBPF: { | ||||||
convert_to_long(arg4); | ||||||
zend_long fval = zval_try_get_long(arg4, &failed); | ||||||
if (failed) { | ||||||
zend_argument_type_error(4, "must be an int, %s given", zend_zval_value_name(arg4)); | ||||||
|
zend_argument_type_error(4, "must be an int, %s given", zend_zval_value_name(arg4)); | |
zend_argument_type_error(4, "must be of type int, %s given", zend_zval_value_name(arg4)); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--TEST-- | ||
socket_set_option() with SO_RCVTIMEO/SO_SNDTIMEO/SO_LINGER | ||
--EXTENSIONS-- | ||
sockets | ||
--FILE-- | ||
<?php | ||
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | ||
if (!$socket) { | ||
die('Unable to create AF_INET socket [socket]'); | ||
} | ||
$options_1 = array("sec" => 1, "usec" => "aaaaa"); | ||
$options_2 = array("sec" => new stdClass(), "usec" => "1"); | ||
$options_3 = array("l_onoff" => "aaaa", "l_linger" => "1"); | ||
$options_4 = array("l_onoff" => "1", "l_linger" => []); | ||
|
||
try { | ||
socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, $options_1); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
|
||
try { | ||
socket_set_option( $socket, SOL_SOCKET, SO_SNDTIMEO, $options_2); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
try { | ||
socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_3); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
try { | ||
socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_4); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
?> | ||
--EXPECT-- | ||
socket_set_option(): Argument #4 ($value) "usec" must be an int, string given | ||
socket_set_option(): Argument #4 ($value) "sec" must be an int, stdClass given | ||
socket_set_option(): Argument #4 ($value) "l_onoff" must be an int, string given | ||
socket_set_option(): Argument #4 ($value) "l_linger" must be an int, array given |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bleh the indent doesn't match here. I would say to not bother, or remove the param name alignment.