summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorMartin Schröder <m.schroeder2007@gmail.com>2020-07-12 20:56:47 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-07-14 10:35:45 +0200
commit547d98b81d674c48f04eab5c24aa065eba4838cc (patch)
treec74b563738e221d80224562c0c3a248f2e102ce1 /win32
parent1a00d015be4f5c1457146022c4d692a03d95154b (diff)
downloadphp-git-547d98b81d674c48f04eab5c24aa065eba4838cc.tar.gz
Support socketpairs in proc_open()
Closes GH-5777.
Diffstat (limited to 'win32')
-rw-r--r--win32/sockets.c33
-rw-r--r--win32/sockets.h1
2 files changed, 22 insertions, 12 deletions
diff --git a/win32/sockets.c b/win32/sockets.c
index c38d2bccbc..0a9a230df5 100644
--- a/win32/sockets.c
+++ b/win32/sockets.c
@@ -24,34 +24,33 @@
#include "php.h"
-PHPAPI int socketpair(int domain, int type, int protocol, SOCKET sock[2])
+PHPAPI int socketpair_win32(int domain, int type, int protocol, SOCKET sock[2], int overlapped)
{
struct sockaddr_in address;
SOCKET redirect;
int size = sizeof(address);
- if(domain != AF_INET) {
+ if (domain != AF_INET) {
WSASetLastError(WSAENOPROTOOPT);
return -1;
}
- sock[0] = sock[1] = redirect = INVALID_SOCKET;
-
+ sock[1] = redirect = INVALID_SOCKET;
- sock[0] = socket(domain, type, protocol);
+ sock[0] = socket(domain, type, protocol);
if (INVALID_SOCKET == sock[0]) {
goto error;
}
address.sin_addr.s_addr = INADDR_ANY;
- address.sin_family = AF_INET;
- address.sin_port = 0;
+ address.sin_family = AF_INET;
+ address.sin_port = 0;
- if (bind(sock[0], (struct sockaddr*)&address, sizeof(address)) != 0) {
+ if (bind(sock[0], (struct sockaddr *) &address, sizeof(address)) != 0) {
goto error;
}
- if(getsockname(sock[0], (struct sockaddr *)&address, &size) != 0) {
+ if (getsockname(sock[0], (struct sockaddr *) &address, &size) != 0) {
goto error;
}
@@ -59,17 +58,22 @@ PHPAPI int socketpair(int domain, int type, int protocol, SOCKET sock[2])
goto error;
}
- sock[1] = socket(domain, type, protocol);
+ if (overlapped) {
+ sock[1] = socket(domain, type, protocol);
+ } else {
+ sock[1] = WSASocket(domain, type, protocol, NULL, 0, 0);
+ }
+
if (INVALID_SOCKET == sock[1]) {
goto error;
}
address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- if(connect(sock[1], (struct sockaddr*)&address, sizeof(address)) != 0) {
+ if (connect(sock[1], (struct sockaddr *) &address, sizeof(address)) != 0) {
goto error;
}
- redirect = accept(sock[0],(struct sockaddr*)&address, &size);
+ redirect = accept(sock[0], (struct sockaddr *) &address, &size);
if (INVALID_SOCKET == redirect) {
goto error;
}
@@ -86,3 +90,8 @@ error:
WSASetLastError(WSAECONNABORTED);
return -1;
}
+
+PHPAPI int socketpair(int domain, int type, int protocol, SOCKET sock[2])
+{
+ return socketpair_win32(domain, type, protocol, sock, 1);
+}
diff --git a/win32/sockets.h b/win32/sockets.h
index f254133cc8..2b2b5c4712 100644
--- a/win32/sockets.h
+++ b/win32/sockets.h
@@ -22,6 +22,7 @@
#ifndef PHP_WIN32_SOCKETS_H
#define PHP_WIN32_SOCKETS_H
+PHPAPI int socketpair_win32(int domain, int type, int protocol, SOCKET sock[2], int overlapped);
PHPAPI int socketpair(int domain, int type, int protocol, SOCKET sock[2]);
#endif