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

NEWS
ext/sockets/sockets.c

diff --git a/NEWS b/NEWS
index 8b31b01e1d2e1e1dbc41ed364b4c86e8e71076e2..c44c3704ac8dbfe31e6cac70db9c7fcce0548432 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ PHP                                                                        NEWS
 - Fixed bug #35017 (Exception thrown in error handler may cause unexpected
   behavior). (Dmitry)
 - Fixed bug #35014 (array_product() always returns 0). (Ilia)
+- Fixed bug #34851 (SO_RECVTIMEO and SO_SNDTIMEO socket options expect integer
+  parameter on Windows). (Mike)
 
 28 Oct 2005, PHP 5.1 Release Candidate 4
 - Fixed fgetcsv() and fputcsv() inconsistency. (Dmitry)
index 4ceeecfb9f91e95572296cd7c43d084461079493..1711a4e2351726922e92d17a81eb0115a68e33d5 100644 (file)
@@ -1506,6 +1506,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;
@@ -1533,12 +1534,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);
                        
@@ -1568,7 +1581,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;
        
@@ -1628,11 +1641,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);