]> granicus.if.org Git - php/commitdiff
- fixed bug #34851 (SO_RECVTIMEO and SO_SNDTIMEO socket options expect integer
authorMichael Wallner <mike@php.net>
Thu, 3 Nov 2005 14:58:43 +0000 (14:58 +0000)
committerMichael Wallner <mike@php.net>
Thu, 3 Nov 2005 14:58:43 +0000 (14:58 +0000)
  parameter on Windows)

NEWS
ext/sockets/sockets.c

diff --git a/NEWS b/NEWS
index 77288da862eb26689fd2c6594d71cd543582cd61..bce9a5032043f512f8ed5a705faac9eef42c9fdf 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ PHP 4                                                                      NEWS
 - Fixed bug #35059 (Apache2 crash with mod_rewrite). (Ilia)
 - Fixed bug #34996 (ImageTrueColorToPalette() crashes when ncolors is 
   zero). (Tony)
+- Fixed bug #34851 (SO_RECVTIMEO and SO_SNDTIMEO socket options expect integer
+  parameter on Windows). (Mike)
 - Fixed bug #33760 (cURL needs to implement CRYPTO_callback functions to prevent
   locking). (Mike)
 
index 2a390acaadc50ff07b76f71235a09b8201872887..554d4df66cebfb2ae731ab4d892065618464cbde 100644 (file)
@@ -1842,6 +1842,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;
@@ -1871,12 +1872,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
 
                        if (array_init(return_value) == FAILURE) {
                                RETURN_FALSE;
@@ -1908,7 +1921,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;
        
@@ -1968,11 +1981,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);