Skip to content

Commit 07cd468

Browse files
authored
ext/sockets: socket_get_option/socket_set_option timeout type on win32. (#17123)
For SO_SNDTIMEO/SO_RCVTIMEO, normally the timeout ought to be of DWORD/unsigned long.
1 parent 3968dbf commit 07cd468

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ext/sockets/sockets.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ PHP_FUNCTION(socket_get_option)
16451645
struct linger linger_val;
16461646
struct timeval tv;
16471647
#ifdef PHP_WIN32
1648-
int timeout = 0;
1648+
DWORD timeout = 0;
16491649
#endif
16501650
socklen_t optlen;
16511651
php_socket *php_sock;
@@ -1757,15 +1757,15 @@ PHP_FUNCTION(socket_get_option)
17571757
RETURN_FALSE;
17581758
}
17591759
#else
1760-
optlen = sizeof(int);
1760+
optlen = sizeof(timeout);
17611761

17621762
if (getsockopt(php_sock->bsd_socket, level, optname, (char*)&timeout, &optlen) != 0) {
17631763
PHP_SOCKET_ERROR(php_sock, "Unable to retrieve socket option", errno);
17641764
RETURN_FALSE;
17651765
}
17661766

1767-
tv.tv_sec = timeout ? timeout / 1000 : 0;
1768-
tv.tv_usec = timeout ? (timeout * 1000) % 1000000 : 0;
1767+
tv.tv_sec = timeout ? (long)(timeout / 1000) : 0;
1768+
tv.tv_usec = timeout ? (long)((timeout * 1000) % 1000000) : 0;
17691769
#endif
17701770

17711771
array_init(return_value);
@@ -1874,7 +1874,7 @@ PHP_FUNCTION(socket_set_option)
18741874
php_socket *php_sock;
18751875
int ov, optlen, retval;
18761876
#ifdef PHP_WIN32
1877-
int timeout;
1877+
DWORD timeout;
18781878
#else
18791879
struct timeval tv;
18801880
#endif
@@ -2019,7 +2019,7 @@ PHP_FUNCTION(socket_set_option)
20192019
opt_ptr = &tv;
20202020
#else
20212021
timeout = Z_LVAL_P(sec) * 1000 + Z_LVAL_P(usec) / 1000;
2022-
optlen = sizeof(int);
2022+
optlen = sizeof(timeout);
20232023
opt_ptr = &timeout;
20242024
#endif
20252025
break;

0 commit comments

Comments
 (0)