summaryrefslogtreecommitdiff
path: root/ext/sockets
diff options
context:
space:
mode:
Diffstat (limited to 'ext/sockets')
-rw-r--r--ext/sockets/config.m42
-rw-r--r--ext/sockets/sockets.c39
-rw-r--r--ext/sockets/tests/bug63000.phpt3
-rw-r--r--ext/sockets/tests/mcast_ipv4_recv.phpt1
-rw-r--r--ext/sockets/tests/socket_send.phpt3
-rw-r--r--ext/sockets/tests/socket_send_win32.phpt43
-rw-r--r--ext/sockets/tests/socket_sendrecvmsg_multi_msg-unix.phpt (renamed from ext/sockets/tests/socket_sendrecvmsg_multi_msg-win32.phpt)29
-rw-r--r--ext/sockets/tests/socket_sendrecvmsg_multi_msg.phpt27
8 files changed, 42 insertions, 105 deletions
diff --git a/ext/sockets/config.m4 b/ext/sockets/config.m4
index 277a3a1dcd..525d7c011a 100644
--- a/ext/sockets/config.m4
+++ b/ext/sockets/config.m4
@@ -17,7 +17,7 @@ if test "$PHP_SOCKETS" != "no"; then
fi
AC_CHECK_FUNCS([hstrerror socketpair if_nametoindex if_indextoname])
- AC_CHECK_HEADERS([netdb.h netinet/tcp.h sys/un.h sys/sockio.h errno.h])
+ AC_CHECK_HEADERS([netdb.h netinet/tcp.h sys/un.h sys/sockio.h])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <sys/socket.h>
diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c
index e8e689f83a..748f210128 100644
--- a/ext/sockets/sockets.c
+++ b/ext/sockets/sockets.c
@@ -37,6 +37,7 @@
# include <Ws2tcpip.h>
# include "php_sockets.h"
# include <win32/sockets.h>
+# include <win32/winutil.h>
#else
# include <sys/types.h>
# include <sys/socket.h>
@@ -649,12 +650,10 @@ char *sockets_strerror(int error) /* {{{ */
}
#else
{
- LPTSTR tmp = NULL;
+ char *tmp = php_win32_error_to_msg(error);
buf = NULL;
- if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &tmp, 0, NULL)
- ) {
+ if (tmp[0]) {
if (SOCKETS_G(strerror_buf)) {
efree(SOCKETS_G(strerror_buf));
}
@@ -2822,22 +2821,16 @@ PHP_FUNCTION(socket_wsaprotocol_info_export)
if (SOCKET_ERROR == WSADuplicateSocket(socket->bsd_socket, (DWORD)target_pid, &wi)) {
DWORD err = WSAGetLastError();
- LPSTR buf = NULL;
-
- if (!FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- err,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPSTR)&buf,
- 0, NULL)) {
+ char *buf = php_win32_error_to_msg(err);
+
+ if (!buf[0]) {
php_error_docref(NULL, E_WARNING, "Unable to export WSA protocol info [0x%08lx]", err);
} else {
php_error_docref(NULL, E_WARNING, "Unable to export WSA protocol info [0x%08lx]: %s", err, buf);
}
+ php_win32_error_msg_free(buf);
+
RETURN_FALSE;
}
@@ -2900,22 +2893,16 @@ PHP_FUNCTION(socket_wsaprotocol_info_import)
sock = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, &wi, 0, 0);
if (INVALID_SOCKET == sock) {
DWORD err = WSAGetLastError();
- LPSTR buf = NULL;
-
- if (!FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- err,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPSTR)&buf,
- 0, NULL)) {
+ char *buf = php_win32_error_to_msg(err);
+
+ if (!buf[0]) {
php_error_docref(NULL, E_WARNING, "Unable to import WSA protocol info [0x%08lx]", err);
} else {
php_error_docref(NULL, E_WARNING, "Unable to import WSA protocol info [0x%08lx]: %s", err, buf);
}
+ php_win32_error_msg_free(buf);
+
RETURN_FALSE;
}
diff --git a/ext/sockets/tests/bug63000.phpt b/ext/sockets/tests/bug63000.phpt
index a467d143c6..024f784ccb 100644
--- a/ext/sockets/tests/bug63000.phpt
+++ b/ext/sockets/tests/bug63000.phpt
@@ -5,9 +5,6 @@ Bug #63000: Multicast on OSX
if (!extension_loaded('sockets')) {
die('skip sockets extension not available.');
}
-if (PHP_OS !== 'Darwin') {
- die('skip Is not OSX.');
-}
--FILE--
<?php
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
diff --git a/ext/sockets/tests/mcast_ipv4_recv.phpt b/ext/sockets/tests/mcast_ipv4_recv.phpt
index fc92563e84..f56b21a2fa 100644
--- a/ext/sockets/tests/mcast_ipv4_recv.phpt
+++ b/ext/sockets/tests/mcast_ipv4_recv.phpt
@@ -5,6 +5,7 @@ Multicast support: IPv4 receive options
if (!extension_loaded('sockets')) {
die('skip sockets extension not available.');
}
+if (getenv('SKIP_ONLINE_TESTS')) die('skip online test');
$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$br = socket_bind($s, '0.0.0.0', 3000);
$so = socket_set_option($s, IPPROTO_IP, MCAST_JOIN_GROUP, array(
diff --git a/ext/sockets/tests/socket_send.phpt b/ext/sockets/tests/socket_send.phpt
index a11e0d7732..dd6be6898b 100644
--- a/ext/sockets/tests/socket_send.phpt
+++ b/ext/sockets/tests/socket_send.phpt
@@ -8,9 +8,6 @@ if (getenv("SKIP_ONLINE_TESTS")) die("skip online test");
if (!extension_loaded('sockets')) {
die('SKIP sockets extension not available.');
}
-if(substr(PHP_OS, 0, 3) == 'WIN' ) {
- die('skip not for windows');
-}
?>
--FILE--
<?php
diff --git a/ext/sockets/tests/socket_send_win32.phpt b/ext/sockets/tests/socket_send_win32.phpt
deleted file mode 100644
index 3f53dfc5a2..0000000000
--- a/ext/sockets/tests/socket_send_win32.phpt
+++ /dev/null
@@ -1,43 +0,0 @@
---TEST--
-int socket_send ( resource $socket , string $buf , int $len , int $flags );
---CREDITS--
-marcosptf - <marcosptf@yahoo.com.br> - #phparty7 - @phpsp - novatec/2015 - sao paulo - br
---SKIPIF--
-<?php
-if (!extension_loaded('sockets')) {
- die('SKIP sockets extension not available.');
-}
-if(substr(PHP_OS, 0, 3) != 'WIN' ) {
- die('skip windows only test');
-}
-?>
---FILE--
-<?php
-$port = 80;
-$host = "yahoo.com";
-$stringSocket = "send_socket_to_connected_socket";
-$stringSocketLength = strlen($stringSocket);
-
-$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
-$socketConn = socket_connect($socket, $host, $port);
-
-if(socket_send($socket, $stringSocket, $stringSocketLength, MSG_OOB)===$stringSocketLength){
- print("okey\n");
-}
-
-if(socket_send($socket, $stringSocket, $stringSocketLength, MSG_DONTROUTE)===$stringSocketLength){
- print("okey\n");
-}
-?>
-<?php
-socket_close($socket);
-unset($port);
-unset($host);
-unset($stringSocket);
-unset($stringSocketLength);
-unset($socket);
-unset($socketConn);
-?>
---EXPECT--
-okey
-okey
diff --git a/ext/sockets/tests/socket_sendrecvmsg_multi_msg-win32.phpt b/ext/sockets/tests/socket_sendrecvmsg_multi_msg-unix.phpt
index 8de2bb5a97..6b46f33715 100644
--- a/ext/sockets/tests/socket_sendrecvmsg_multi_msg-win32.phpt
+++ b/ext/sockets/tests/socket_sendrecvmsg_multi_msg-unix.phpt
@@ -1,18 +1,24 @@
--TEST--
-sendmsg()/recvmsg(): test ability to receive multiple messages (WIN32)
+sendmsg()/recvmsg(): test ability to receive multiple messages
--SKIPIF--
<?php
if (!extension_loaded('sockets'))
die('skip sockets extension not available.');
+
+require 'ipv6_skipif.inc';
+
if (!defined('IPPROTO_IPV6'))
die('skip IPv6 not available.');
-if (substr(PHP_OS, 0, 3) != 'WIN')
- die('skip Only for Windows!');
+if (substr(PHP_OS, 0, 3) == 'WIN')
+ die('skip Not for the Windows!');
/* Windows supports IPV6_RECVTCLASS and is able to receive the tclass via
* WSARecvMsg (though only the top 6 bits seem to reported), but WSASendMsg
- * does not accept IPV6_TCLASS messages. We still test that sendmsg() works
- * corectly by sending an IPV6_PKTINFO message that will have no effect */
+ * does not accept IPV6_TCLASS messages */
+if (!defined('IPV6_RECVPKTINFO')) {
+ die('skip IPV6_RECVPKTINFO not available.');
+}
+?>
--FILE--
<?php
include __DIR__."/mcast_helpers.php.inc";
@@ -39,11 +45,8 @@ $r = socket_sendmsg($sends1, [
"iov" => ["test ", "thing", "\n"],
"control" => [[
"level" => IPPROTO_IPV6,
- "type" => IPV6_PKTINFO,
- "data" => [
- 'addr' => '::1',
- 'ifindex' => 1 /* we're assuming loopback is 1. Is this a safe assumption? */
- ],
+ "type" => IPV6_TCLASS,
+ "data" => 40,
]]
], 0);
var_dump($r);
@@ -60,10 +63,10 @@ print_r($data);
--EXPECTF--
creating send socket
-resource(%d) of type (Socket)
+resource(5) of type (Socket)
bool(true)
creating receive socket
-resource(%d) of type (Socket)
+resource(6) of type (Socket)
bool(true)
int(11)
Array
@@ -95,7 +98,7 @@ Array
(
[level] => %d
[type] => %d
- [data] => 0
+ [data] => 40
)
)
diff --git a/ext/sockets/tests/socket_sendrecvmsg_multi_msg.phpt b/ext/sockets/tests/socket_sendrecvmsg_multi_msg.phpt
index 6b46f33715..750b22dabf 100644
--- a/ext/sockets/tests/socket_sendrecvmsg_multi_msg.phpt
+++ b/ext/sockets/tests/socket_sendrecvmsg_multi_msg.phpt
@@ -1,24 +1,16 @@
--TEST--
-sendmsg()/recvmsg(): test ability to receive multiple messages
+sendmsg()/recvmsg(): test ability to receive multiple messages (WIN32)
--SKIPIF--
<?php
if (!extension_loaded('sockets'))
die('skip sockets extension not available.');
-
-require 'ipv6_skipif.inc';
-
if (!defined('IPPROTO_IPV6'))
die('skip IPv6 not available.');
-if (substr(PHP_OS, 0, 3) == 'WIN')
- die('skip Not for the Windows!');
/* Windows supports IPV6_RECVTCLASS and is able to receive the tclass via
* WSARecvMsg (though only the top 6 bits seem to reported), but WSASendMsg
- * does not accept IPV6_TCLASS messages */
+ * does not accept IPV6_TCLASS messages. We still test that sendmsg() works
+ * corectly by sending an IPV6_PKTINFO message that will have no effect */
-if (!defined('IPV6_RECVPKTINFO')) {
- die('skip IPV6_RECVPKTINFO not available.');
-}
-?>
--FILE--
<?php
include __DIR__."/mcast_helpers.php.inc";
@@ -45,8 +37,11 @@ $r = socket_sendmsg($sends1, [
"iov" => ["test ", "thing", "\n"],
"control" => [[
"level" => IPPROTO_IPV6,
- "type" => IPV6_TCLASS,
- "data" => 40,
+ "type" => IPV6_PKTINFO,
+ "data" => [
+ 'addr' => '::1',
+ 'ifindex' => 1 /* we're assuming loopback is 1. Is this a safe assumption? */
+ ],
]]
], 0);
var_dump($r);
@@ -63,10 +58,10 @@ print_r($data);
--EXPECTF--
creating send socket
-resource(5) of type (Socket)
+resource(%d) of type (Socket)
bool(true)
creating receive socket
-resource(6) of type (Socket)
+resource(%d) of type (Socket)
bool(true)
int(11)
Array
@@ -98,7 +93,7 @@ Array
(
[level] => %d
[type] => %d
- [data] => 40
+ [data] => 0
)
)