Skip to content

Commit 153c26d

Browse files
Set default values for ___domain, type, and protocol in socket_create
This commit modifies the `socket_create` function in the PHP Socket extension to set default values for the `___domain`, `type`, and `protocol` parameters if the user doesn't provide any arguments. The default values are set as follows: - `___domain`: Set to `AF_INET` (IPv4) on Windows systems, and `AF_UNIX` (Unix ___domain sockets) on non-Windows systems. - `type`: Set to `SOCK_STREAM` (TCP). - `protocol`: Set to `SOL_TCP`. If the user provides arguments to the `socket_create` function, those values will override the default values set by this commit.
1 parent 8f7d284 commit 153c26d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ext/sockets/sockets.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,8 +1053,14 @@ PHP_FUNCTION(socket_getpeername)
10531053
/* {{{ Creates an endpoint for communication in the ___domain specified by ___domain, of type specified by type */
10541054
PHP_FUNCTION(socket_create)
10551055
{
1056-
zend_long ___domain, type, protocol;
1057-
php_socket *php_sock;
1056+
zend_long ___domain, type = SOCK_STREAM, protocol = SOL_TCP;
1057+
php_socket *php_sock;
1058+
1059+
if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
1060+
___domain = AF_INET;
1061+
} else {
1062+
___domain = AF_UNIX;
1063+
}
10581064

10591065
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &___domain, &type, &protocol) == FAILURE) {
10601066
RETURN_THROWS();

0 commit comments

Comments
 (0)