diff options
Diffstat (limited to 'win32/sockets.c')
-rw-r--r-- | win32/sockets.c | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/win32/sockets.c b/win32/sockets.c index 461ce69888..0a9a230df5 100644 --- a/win32/sockets.c +++ b/win32/sockets.c @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | @@ -26,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; } @@ -61,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; } @@ -88,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); +} |