From 547d98b81d674c48f04eab5c24aa065eba4838cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schr=C3=B6der?= Date: Sun, 12 Jul 2020 20:56:47 +0200 Subject: Support socketpairs in proc_open() Closes GH-5777. --- win32/sockets.c | 33 +++++++++++++++++++++------------ win32/sockets.h | 1 + 2 files changed, 22 insertions(+), 12 deletions(-) (limited to 'win32') 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 -- cgit v1.2.1