Skip to content

Commit f578bb0

Browse files
committed
Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4: updated NEWS Fixed stream_socket_pair() on Windows x64 and
2 parents 0720804 + b3aa3c2 commit f578bb0

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

ext/standard/streamsfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ PHP_FUNCTION(stream_socket_pair)
5151
{
5252
long domain, type, protocol;
5353
php_stream *s1, *s2;
54-
int pair[2];
54+
php_socket_t pair[2];
5555

5656
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
5757
&domain, &type, &protocol)) {

win32/sockets.c

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,54 @@ PHPAPI int socketpair(int domain, int type, int protocol, SOCKET sock[2])
3939
return -1;
4040
}
4141

42+
sock[0] = sock[1] = redirect = INVALID_SOCKET;
4243

43-
sock[0] = socket(domain, type, protocol);
44-
address.sin_addr.s_addr = INADDR_ANY;
45-
address.sin_family = AF_INET;
46-
address.sin_port = 0;
4744

48-
bind(sock[0], (struct sockaddr*)&address, sizeof(address));
45+
sock[0] = socket(domain, type, protocol);
46+
if (INVALID_SOCKET == sock[0]) {
47+
goto error;
48+
}
49+
50+
address.sin_addr.s_addr = INADDR_ANY;
51+
address.sin_family = AF_INET;
52+
address.sin_port = 0;
53+
54+
if (bind(sock[0], (struct sockaddr*)&address, sizeof(address)) != 0) {
55+
goto error;
56+
}
4957

5058
if(getsockname(sock[0], (struct sockaddr *)&address, &size) != 0) {
59+
goto error;
60+
}
61+
62+
if (listen(sock[0], 2) != 0) {
63+
goto error;
64+
}
65+
66+
sock[1] = socket(domain, type, protocol);
67+
if (INVALID_SOCKET == sock[1]) {
68+
goto error;
5169
}
5270

53-
listen(sock[0], 2);
54-
sock[1] = socket(domain, type, protocol);
5571
address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
72+
if(connect(sock[1], (struct sockaddr*)&address, sizeof(address)) != 0) {
73+
goto error;
74+
}
5675

57-
connect(sock[1], (struct sockaddr*)&address, sizeof(address));
5876
redirect = accept(sock[0],(struct sockaddr*)&address, &size);
77+
if (INVALID_SOCKET == redirect) {
78+
goto error;
79+
}
5980

6081
closesocket(sock[0]);
6182
sock[0] = redirect;
6283

63-
if(sock[0] == INVALID_SOCKET ) {
64-
closesocket(sock[0]);
65-
closesocket(sock[1]);
66-
WSASetLastError(WSAECONNABORTED);
67-
return -1;
68-
}
69-
7084
return 0;
85+
86+
error:
87+
closesocket(redirect);
88+
closesocket(sock[0]);
89+
closesocket(sock[1]);
90+
WSASetLastError(WSAECONNABORTED);
91+
return -1;
7192
}

0 commit comments

Comments
 (0)