Skip to content

Commit 51cac49

Browse files
committed
Move up to IPPROTO_TCP block
1 parent 1f9ce74 commit 51cac49

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

ext/sockets/sockets.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,28 @@ PHP_FUNCTION(socket_set_option)
21302130
}
21312131
#endif
21322132

2133+
#if defined(TCP_USER_TIMEOUT)
2134+
case TCP_USER_TIMEOUT: {
2135+
zend_long timeout = zval_get_long(arg4);
2136+
2137+
// TCP_USER_TIMEOUT unsigned int
2138+
if (timeout < 0 || timeout > UINT_MAX) {
2139+
zend_argument_value_error(4, "must be of between 0 and %u", UINT_MAX);
2140+
RETURN_THROWS();
2141+
}
2142+
2143+
unsigned int val = (unsigned int)timeout;
2144+
optlen = sizeof(val);
2145+
opt_ptr = &val;
2146+
if (setsockopt(php_sock->bsd_socket, level, optname, opt_ptr, optlen) != 0) {
2147+
PHP_SOCKET_ERROR(php_sock, "Unable to set socket option", errno);
2148+
RETURN_FALSE;
2149+
}
2150+
2151+
RETURN_TRUE;
2152+
}
2153+
#endif
2154+
21332155
}
21342156
}
21352157

@@ -2329,23 +2351,6 @@ PHP_FUNCTION(socket_set_option)
23292351
}
23302352
#endif
23312353

2332-
#if defined(TCP_USER_TIMEOUT)
2333-
case TCP_USER_TIMEOUT: {
2334-
zend_long timeout = zval_get_long(arg4);
2335-
2336-
// TCP_USER_TIMEOUT unsigned int
2337-
if (timeout < 0 || timeout > UINT_MAX) {
2338-
zend_argument_value_error(4, "must be of between 0 and %u", UINT_MAX);
2339-
RETURN_THROWS();
2340-
}
2341-
2342-
unsigned int val = (unsigned int)timeout;
2343-
optlen = sizeof(val);
2344-
opt_ptr = &val;
2345-
break;
2346-
}
2347-
#endif
2348-
23492354
#if defined(UDP_SEGMENT)
23502355
case UDP_SEGMENT: {
23512356
ov = zval_get_long(arg4);

0 commit comments

Comments
 (0)