kalle           Fri Jan 23 15:49:50 2009 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/win32      sockets.c sockets.h 

  Removed files:               
    /php-src/ext/sockets        php_sockets_win.c php_sockets_win.h 

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/sockets        config.w32 php_sockets.h sockets.c 
    /php-src/ext/standard       streamsfuncs.c streamsfuncs.h 
    /php-src/ext/standard/tests/streams stream_socket_pair.phpt 
    /php-src/win32/build        config.w32 config.w32.h.in 
  Log:
  MFH: Windows support for stream_socket_pair(), by moving the socketpair() 
implementation from ext/sockets to win32/
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.471&r2=1.2027.2.547.2.965.2.472&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.471 
php-src/NEWS:1.2027.2.547.2.965.2.472
--- php-src/NEWS:1.2027.2.547.2.965.2.471       Tue Jan 20 20:28:04 2009
+++ php-src/NEWS        Fri Jan 23 15:49:45 2009
@@ -43,6 +43,7 @@
 - Added ICU support to SQLite3 when using the bundled version. (Scott)
 - Added pixelation support in imagefilter(). (Takeshi Abe, Kalle)
 - Added SplObjectStorage::addAll/removeAll. (Etienne)
+- Added Windows support for stream_socket_pair(). (Kalle)
 
 - Re-added socket_create_pair() for Windows in sockets extension. (Kalle)
 
http://cvs.php.net/viewvc.cgi/php-src/ext/sockets/config.w32?r1=1.1.8.1&r2=1.1.8.2&diff_format=u
Index: php-src/ext/sockets/config.w32
diff -u php-src/ext/sockets/config.w32:1.1.8.1 
php-src/ext/sockets/config.w32:1.1.8.2
--- php-src/ext/sockets/config.w32:1.1.8.1      Mon Jun 23 18:40:29 2008
+++ php-src/ext/sockets/config.w32      Fri Jan 23 15:49:48 2009
@@ -1,4 +1,4 @@
-// $Id: config.w32,v 1.1.8.1 2008/06/23 18:40:29 pajoye Exp $
+// $Id: config.w32,v 1.1.8.2 2009/01/23 15:49:48 kalle Exp $
 // vim:ft=javascript
 
 ARG_ENABLE("sockets", "SOCKETS support", "no");
@@ -6,7 +6,7 @@
 if (PHP_SOCKETS != "no") {
        if (CHECK_LIB("ws2_32.lib", "sockets", PHP_SOCKETS)
        && CHECK_HEADER_ADD_INCLUDE("winsock.h", "CFLAGS_SOCKETS")) {
-               EXTENSION('sockets', 'sockets.c php_sockets_win.c');
+               EXTENSION('sockets', 'sockets.c');
                AC_DEFINE('HAVE_SOCKETS', 1);
        } else {
                WARNING("sockets not enabled; libraries and headers not found");
http://cvs.php.net/viewvc.cgi/php-src/ext/sockets/php_sockets.h?r1=1.36.2.1.2.4.2.4&r2=1.36.2.1.2.4.2.5&diff_format=u
Index: php-src/ext/sockets/php_sockets.h
diff -u php-src/ext/sockets/php_sockets.h:1.36.2.1.2.4.2.4 
php-src/ext/sockets/php_sockets.h:1.36.2.1.2.4.2.5
--- php-src/ext/sockets/php_sockets.h:1.36.2.1.2.4.2.4  Thu Jan  1 05:24:29 2009
+++ php-src/ext/sockets/php_sockets.h   Fri Jan 23 15:49:48 2009
@@ -22,7 +22,7 @@
 #ifndef PHP_SOCKETS_H
 #define PHP_SOCKETS_H
 
-/* $Id: php_sockets.h,v 1.36.2.1.2.4.2.4 2009/01/01 05:24:29 kalle Exp $ */
+/* $Id: php_sockets.h,v 1.36.2.1.2.4.2.5 2009/01/23 15:49:48 kalle Exp $ */
 
 #if HAVE_SOCKETS
 
@@ -43,7 +43,7 @@
 
 PHP_FUNCTION(socket_select);
 PHP_FUNCTION(socket_create_listen);
-#if defined(HAVE_SOCKETPAIR) || defined(PHP_WIN32)
+#ifdef PHP_WIN32
 PHP_FUNCTION(socket_create_pair);
 #endif
 PHP_FUNCTION(socket_accept);
@@ -84,6 +84,13 @@
        int             blocking;
 } php_socket;
 
+#ifdef PHP_WIN32
+struct sockaddr_un {
+       short   sun_family;
+       char    sun_path[108];
+};
+#endif
+
 /* Prototypes */
 #ifdef ilia_0 /* not needed, only causes a compiler warning */
 static int php_open_listen_sock(php_socket **php_sock, int port, int backlog 
TSRMLS_DC);
http://cvs.php.net/viewvc.cgi/php-src/ext/sockets/sockets.c?r1=1.171.2.9.2.14.2.13&r2=1.171.2.9.2.14.2.14&diff_format=u
Index: php-src/ext/sockets/sockets.c
diff -u php-src/ext/sockets/sockets.c:1.171.2.9.2.14.2.13 
php-src/ext/sockets/sockets.c:1.171.2.9.2.14.2.14
--- php-src/ext/sockets/sockets.c:1.171.2.9.2.14.2.13   Thu Jan  1 05:24:29 2009
+++ php-src/ext/sockets/sockets.c       Fri Jan 23 15:49:48 2009
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: sockets.c,v 1.171.2.9.2.14.2.13 2009/01/01 05:24:29 kalle Exp $ */
+/* $Id: sockets.c,v 1.171.2.9.2.14.2.14 2009/01/23 15:49:48 kalle Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -39,8 +39,17 @@
 # include <windows.h>
 # include <Ws2tcpip.h>
 # include "php_sockets.h"
-# include "php_sockets_win.h"
+# include "win32/sockets.h"
 # define IS_INVALID_SOCKET(a)  (a->bsd_socket == INVALID_SOCKET)
+# define EPROTONOSUPPORT       WSAEPROTONOSUPPORT
+# define ECONNRESET            WSAECONNRESET
+# ifdef errno
+#  undef errno
+# endif
+# define errno                 WSAGetLastError()
+# define h_errno               WSAGetLastError()
+# define set_errno(a)          WSASetLastError(a)
+# define close(a)              closesocket(a)
 #else
 # include "php_sockets.h"
 # include <sys/types.h>
@@ -223,7 +232,7 @@
        ZEND_ARG_INFO(0, optval)
 ZEND_END_ARG_INFO()
 
-#if defined(HAVE_SOCKETPAIR) || defined(PHP_WIN32)
+#ifdef HAVE_SOCKETPAIR
 ZEND_BEGIN_ARG_INFO_EX(arginfo_socket_create_pair, 0, 0, 4)
        ZEND_ARG_INFO(0, domain)
        ZEND_ARG_INFO(0, type)
@@ -254,7 +263,7 @@
        PHP_FE(socket_select,                   arginfo_socket_select)
        PHP_FE(socket_create,                   arginfo_socket_create)
        PHP_FE(socket_create_listen,    arginfo_socket_create_listen)
-#if defined(HAVE_SOCKETPAIR) || defined(PHP_WIN32)
+#ifdef HAVE_SOCKETPAIR
        PHP_FE(socket_create_pair,              arginfo_socket_create_pair)
 #endif
        PHP_FE(socket_accept,                   arginfo_socket_accept)
@@ -1867,7 +1876,7 @@
 }
 /* }}} */
 
-#if defined(HAVE_SOCKETPAIR) || defined(PHP_WIN32)
+#ifdef HAVE_SOCKETPAIR
 /* {{{ proto bool socket_create_pair(int domain, int type, int protocol, array 
&fd) U
    Creates a pair of indistinguishable sockets and stores them in fds. */
 PHP_FUNCTION(socket_create_pair)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/streamsfuncs.c?r1=1.58.2.6.2.15.2.33&r2=1.58.2.6.2.15.2.34&diff_format=u
Index: php-src/ext/standard/streamsfuncs.c
diff -u php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.15.2.33 
php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.15.2.34
--- php-src/ext/standard/streamsfuncs.c:1.58.2.6.2.15.2.33      Thu Jan  8 
17:01:58 2009
+++ php-src/ext/standard/streamsfuncs.c Fri Jan 23 15:49:49 2009
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: streamsfuncs.c,v 1.58.2.6.2.15.2.33 2009/01/08 17:01:58 lbarnaud Exp $ 
*/
+/* $Id: streamsfuncs.c,v 1.58.2.6.2.15.2.34 2009/01/23 15:49:49 kalle Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -36,6 +36,7 @@
 typedef unsigned long long php_timeout_ull;
 #else
 #include "win32/select.h"
+#include "win32/sockets.h"
 typedef unsigned __int64 php_timeout_ull;
 #endif
 
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/streamsfuncs.h?r1=1.13.2.1.2.4.2.5&r2=1.13.2.1.2.4.2.6&diff_format=u
Index: php-src/ext/standard/streamsfuncs.h
diff -u php-src/ext/standard/streamsfuncs.h:1.13.2.1.2.4.2.5 
php-src/ext/standard/streamsfuncs.h:1.13.2.1.2.4.2.6
--- php-src/ext/standard/streamsfuncs.h:1.13.2.1.2.4.2.5        Wed Dec 31 
11:15:45 2008
+++ php-src/ext/standard/streamsfuncs.h Fri Jan 23 15:49:49 2009
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: streamsfuncs.h,v 1.13.2.1.2.4.2.5 2008/12/31 11:15:45 sebastian Exp $ 
*/
+/* $Id: streamsfuncs.h,v 1.13.2.1.2.4.2.6 2009/01/23 15:49:49 kalle Exp $ */
 
 /* Flags for stream_socket_client */
 #define PHP_STREAM_CLIENT_PERSISTENT   1
@@ -56,10 +56,13 @@
 PHP_FUNCTION(stream_filter_remove);
 PHP_FUNCTION(stream_socket_enable_crypto);
 PHP_FUNCTION(stream_socket_shutdown);
-PHP_FUNCTION(stream_socket_pair);
 PHP_FUNCTION(stream_is_local);
 PHP_FUNCTION(stream_supports_lock);
 
+#if HAVE_SOCKETPAIR
+PHP_FUNCTION(stream_socket_pair);
+#endif
+
 /*
  * Local variables:
  * tab-width: 4
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/streams/stream_socket_pair.phpt?r1=1.1.2.2&r2=1.1.2.3&diff_format=u
Index: php-src/ext/standard/tests/streams/stream_socket_pair.phpt
diff -u php-src/ext/standard/tests/streams/stream_socket_pair.phpt:1.1.2.2 
php-src/ext/standard/tests/streams/stream_socket_pair.phpt:1.1.2.3
--- php-src/ext/standard/tests/streams/stream_socket_pair.phpt:1.1.2.2  Tue Nov 
 4 16:46:03 2008
+++ php-src/ext/standard/tests/streams/stream_socket_pair.phpt  Fri Jan 23 
15:49:49 2009
@@ -1,12 +1,9 @@
 --TEST--
 stream_socket_pair()
---SKIPIF--
-<?php
-if (substr(PHP_OS, 0, 3) == 'WIN') die("skip: non windows test");
-?>
 --FILE--
 <?php
-$sockets = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
+$domain = (strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? STREAM_PF_INET : 
STREAM_PF_UNIX);
+$sockets = stream_socket_pair($domain, STREAM_SOCK_STREAM, 0);
 var_dump($sockets);
 fwrite($sockets[0], b"foo");
 var_dump(fread($sockets[1], strlen(b"foo")));
http://cvs.php.net/viewvc.cgi/php-src/win32/build/config.w32?r1=1.40.2.8.2.10.2.43&r2=1.40.2.8.2.10.2.44&diff_format=u
Index: php-src/win32/build/config.w32
diff -u php-src/win32/build/config.w32:1.40.2.8.2.10.2.43 
php-src/win32/build/config.w32:1.40.2.8.2.10.2.44
--- php-src/win32/build/config.w32:1.40.2.8.2.10.2.43   Tue Jan 20 01:37:48 2009
+++ php-src/win32/build/config.w32      Fri Jan 23 15:49:49 2009
@@ -1,5 +1,5 @@
 // vim:ft=javascript
-// $Id: config.w32,v 1.40.2.8.2.10.2.43 2009/01/20 01:37:48 pajoye Exp $
+// $Id: config.w32,v 1.40.2.8.2.10.2.44 2009/01/23 15:49:49 kalle Exp $
 // "Master" config file; think of it as a configure.in
 // equivalent.
 
@@ -317,7 +317,7 @@
        php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \
        strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c 
network.c \
        php_open_temporary_file.c php_logos.c output.c internal_functions.c 
php_sprintf.c");
-ADD_SOURCES("win32", "inet.c fnmatch.c");
+ADD_SOURCES("win32", "inet.c fnmatch.c sockets.c");
 
 // Newer versions have it
 if (VCVERS <= 1300) {
http://cvs.php.net/viewvc.cgi/php-src/win32/build/config.w32.h.in?r1=1.7.2.4.2.3.2.9&r2=1.7.2.4.2.3.2.10&diff_format=u
Index: php-src/win32/build/config.w32.h.in
diff -u php-src/win32/build/config.w32.h.in:1.7.2.4.2.3.2.9 
php-src/win32/build/config.w32.h.in:1.7.2.4.2.3.2.10
--- php-src/win32/build/config.w32.h.in:1.7.2.4.2.3.2.9 Tue Jan 20 01:37:48 2009
+++ php-src/win32/build/config.w32.h.in Fri Jan 23 15:49:49 2009
@@ -1,6 +1,6 @@
 /*
        Build Configuration Template for Win32.
-       $Id: config.w32.h.in,v 1.7.2.4.2.3.2.9 2009/01/20 01:37:48 pajoye Exp $
+       $Id: config.w32.h.in,v 1.7.2.4.2.3.2.10 2009/01/23 15:49:49 kalle Exp $
 */
 
 /* Define the minimum supported version */
@@ -147,6 +147,9 @@
 /* Win32 supports strcoll */
 #define HAVE_STRCOLL 1
 
+/* Win32 supports socketpair by the emulation in win32/sockets.c */
+#define HAVE_SOCKETPAIR 1
+
 /* Win32 support proc_open */
 #define PHP_CAN_SUPPORT_PROC_OPEN 1
 

http://cvs.php.net/viewvc.cgi/php-src/win32/sockets.c?view=markup&rev=1.1
Index: php-src/win32/sockets.c
+++ php-src/win32/sockets.c
/*
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2009 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.php.net/license/3_01.txt                                  |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | lice...@php.net so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Authors: Chris Vandomelen <chr...@b0rked.dhs.org>                    |
   |          Sterling Hughes  <sterl...@php.net>                         |
   |                                                                      |
   | WinSock: Daniel Beulshausen <dan...@php4win.de>                      |
   +----------------------------------------------------------------------+
 */

/* $Id: sockets.c,v 1.1 2009/01/23 15:48:58 kalle Exp $ */

/* Code originally from ext/sockets */

#include <stdio.h>
#include <fcntl.h>

#include "php.h"

PHPAPI int socketpair(int domain, int type, int protocol, SOCKET sock[2])
{
        struct sockaddr_in address;
        SOCKET redirect;
        int size = sizeof(address);

        if(domain != AF_INET) {
                WSASetLastError(WSAENOPROTOOPT);
                return -1;
        }


        sock[0]                         = socket(domain, type, protocol);
        address.sin_addr.s_addr         = INADDR_ANY;
        address.sin_family              = AF_INET;
        address.sin_port                = 0;

        bind(sock[0], (struct sockaddr*)&address, sizeof(address));

        if(getsockname(sock[0], (struct sockaddr *)&address, &size) != 0) {
        }

        listen(sock[0], 2);
        sock[1] = socket(domain, type, protocol);       
        address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

        connect(sock[1], (struct sockaddr*)&address, sizeof(address));
        redirect = accept(sock[0],(struct sockaddr*)&address, &size);

        closesocket(sock[0]);
        sock[0] = redirect;

        if(sock[0] == INVALID_SOCKET ) {
                closesocket(sock[0]);
                closesocket(sock[1]);
                WSASetLastError(WSAECONNABORTED);
                return -1;
        }
        
        return 0;
}

http://cvs.php.net/viewvc.cgi/php-src/win32/sockets.h?view=markup&rev=1.1
Index: php-src/win32/sockets.h
+++ php-src/win32/sockets.h
/*
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2009 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.php.net/license/3_01.txt                                  |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | lice...@php.net so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Authors: Chris Vandomelen <chr...@b0rked.dhs.org>                    |
   |          Sterling Hughes  <sterl...@php.net>                         |
   |                                                                      |
   | WinSock: Daniel Beulshausen <dan...@php4win.de>                      |
   +----------------------------------------------------------------------+
 */

/* $Id: sockets.h,v 1.1 2009/01/23 15:48:58 kalle Exp $ */

/* Code originally from ext/sockets */

PHPAPI int socketpair(int domain, int type, int protocol, SOCKET sock[2]);
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to