From: Michael Wallner Date: Thu, 3 Nov 2005 15:01:31 +0000 (+0000) Subject: - MFB44: #34851 (SO_RECVTIMEO and SO_SNDTIMEO socket options expect integer X-Git-Tag: RELEASE_2_0_1~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36d3c24c6e2237a4c564cf2837a685df33006424;p=php - MFB44: #34851 (SO_RECVTIMEO and SO_SNDTIMEO socket options expect integer parameter on Windows) --- diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 44a40a5e01..bf5d0f21b6 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -1504,6 +1504,7 @@ PHP_FUNCTION(socket_get_option) zval *arg1; struct linger linger_val; struct timeval tv; + int timeout = 0; socklen_t optlen; php_socket *php_sock; int other_val; @@ -1531,12 +1532,24 @@ PHP_FUNCTION(socket_get_option) break; case SO_RCVTIMEO: case SO_SNDTIMEO: +#ifndef PHP_WIN32 optlen = sizeof(tv); if (getsockopt(php_sock->bsd_socket, level, optname, (char*)&tv, &optlen) != 0) { PHP_SOCKET_ERROR(php_sock, "unable to retrieve socket option", errno); RETURN_FALSE; } +#else + optlen = sizeof(int); + + if (getsockopt(php_sock->bsd_socket, level, optname, (char*)&timeout, &optlen) != 0) { + PHP_SOCKET_ERROR(php_sock, "unable to retrieve socket option", errno); + RETURN_FALSE; + } + + tv.tv_sec = timeout ? timeout / 1000 : 0; + tv.tv_usec = timeout ? (timeout * 1000) % 1000000 : 0; +#endif array_init(return_value); @@ -1566,7 +1579,7 @@ PHP_FUNCTION(socket_set_option) struct linger lv; struct timeval tv; php_socket *php_sock; - int ov, optlen, retval; + int ov, optlen, retval, timeout; long level, optname; void *opt_ptr; @@ -1626,11 +1639,16 @@ PHP_FUNCTION(socket_set_option) convert_to_long_ex(sec); convert_to_long_ex(usec); +#ifndef PHP_WIN32 tv.tv_sec = Z_LVAL_PP(sec); tv.tv_usec = Z_LVAL_PP(usec); - optlen = sizeof(tv); opt_ptr = &tv; +#else + timeout = Z_LVAL_PP(sec) * 1000 + Z_LVAL_PP(usec) / 1000; + optlen = sizeof(int); + opt_ptr = &timeout; +#endif break; default: convert_to_long_ex(&arg4);