summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/sockets/config.w322
-rw-r--r--ext/sockets/php_sockets.h9
-rw-r--r--ext/sockets/php_sockets_win.c75
-rw-r--r--ext/sockets/php_sockets_win.h47
-rw-r--r--ext/sockets/sockets.c17
-rw-r--r--ext/standard/streamsfuncs.c1
-rw-r--r--ext/standard/streamsfuncs.h5
-rw-r--r--ext/standard/tests/streams/stream_socket_pair.phpt7
8 files changed, 29 insertions, 134 deletions
diff --git a/ext/sockets/config.w32 b/ext/sockets/config.w32
index 3e44356fe7..1672f85b15 100644
--- a/ext/sockets/config.w32
+++ b/ext/sockets/config.w32
@@ -6,7 +6,7 @@ ARG_ENABLE("sockets", "SOCKETS support", "no");
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");
diff --git a/ext/sockets/php_sockets.h b/ext/sockets/php_sockets.h
index f0c9cc5203..aebe3ea4bf 100644
--- a/ext/sockets/php_sockets.h
+++ b/ext/sockets/php_sockets.h
@@ -43,7 +43,7 @@ PHP_RSHUTDOWN_FUNCTION(sockets);
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 @@ typedef struct {
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);
diff --git a/ext/sockets/php_sockets_win.c b/ext/sockets/php_sockets_win.c
deleted file mode 100644
index 809b79c557..0000000000
--- a/ext/sockets/php_sockets_win.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | 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 |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Chris Vandomelen <chrisv@b0rked.dhs.org> |
- | Sterling Hughes <sterling@php.net> |
- | |
- | WinSock: Daniel Beulshausen <daniel@php4win.de> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-
-#ifdef PHP_WIN32
-
-#include <stdio.h>
-#include <fcntl.h>
-
-#include "php.h"
-#include "php_sockets.h"
-#include "php_sockets_win.h"
-
-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) {
- set_errno(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);
-
- close(sock[0]);
- sock[0] = redirect;
-
- if(sock[0] == INVALID_SOCKET ) {
- close(sock[0]);
- close(sock[1]);
- set_errno(WSAECONNABORTED);
- return -1;
- }
-
- return 0;
-}
-
-#endif
diff --git a/ext/sockets/php_sockets_win.h b/ext/sockets/php_sockets_win.h
deleted file mode 100644
index f7e7c55e78..0000000000
--- a/ext/sockets/php_sockets_win.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | 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 |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Chris Vandomelen <chrisv@b0rked.dhs.org> |
- | Sterling Hughes <sterling@php.net> |
- | |
- | WinSock: Daniel Beulshausen <daniel@php4win.de> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-
-#ifdef PHP_WIN32
-
-#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)
-
-struct sockaddr_un {
- short sun_family;
- char sun_path[108];
-};
-
-int socketpair(int domain, int type, int protocol, SOCKET sock[2]);
-int inet_aton(const char *cp, struct in_addr *inp);
-
-#endif
diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c
index d53b8f5b4c..64347ea1e6 100644
--- a/ext/sockets/sockets.c
+++ b/ext/sockets/sockets.c
@@ -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_BEGIN_ARG_INFO_EX(arginfo_socket_set_option, 0, 0, 4)
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 @@ const zend_function_entry sockets_functions[] = {
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 @@ PHP_FUNCTION(socket_set_option)
}
/* }}} */
-#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)
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index 5220cc1555..cdb420c0f7 100644
--- a/ext/standard/streamsfuncs.c
+++ b/ext/standard/streamsfuncs.c
@@ -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
diff --git a/ext/standard/streamsfuncs.h b/ext/standard/streamsfuncs.h
index 19e2c1ef15..a3052bac63 100644
--- a/ext/standard/streamsfuncs.h
+++ b/ext/standard/streamsfuncs.h
@@ -56,10 +56,13 @@ PHP_FUNCTION(stream_filter_append);
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
diff --git a/ext/standard/tests/streams/stream_socket_pair.phpt b/ext/standard/tests/streams/stream_socket_pair.phpt
index 5556d8e22c..203ae982d1 100644
--- a/ext/standard/tests/streams/stream_socket_pair.phpt
+++ b/ext/standard/tests/streams/stream_socket_pair.phpt
@@ -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")));