mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Add stream_socket_pair(), a streams based version of socketpair().
Modified patch from Vincent [six at t0x dot net]
This commit is contained in:
parent
c96a1e0ddf
commit
d10b86f8f4
5 changed files with 48 additions and 0 deletions
|
@ -322,6 +322,7 @@ dnl are usually in libnsl
|
|||
dnl Also, uClibc will bark at linking with glibc's libnsl.
|
||||
|
||||
PHP_CHECK_FUNC(socket, socket)
|
||||
PHP_CHECK_FUNC(socketpair, socket)
|
||||
PHP_CHECK_FUNC(htonl, socket)
|
||||
PHP_CHECK_FUNC(gethostname, nsl)
|
||||
PHP_CHECK_FUNC(gethostbyaddr, nsl)
|
||||
|
|
|
@ -602,6 +602,9 @@ function_entry basic_functions[] = {
|
|||
PHP_FE(stream_socket_recvfrom, fourth_arg_force_ref)
|
||||
PHP_FE(stream_socket_sendto, NULL)
|
||||
PHP_FE(stream_socket_enable_crypto, NULL)
|
||||
#if HAVE_SOCKETPAIR
|
||||
PHP_FE(stream_socket_pair, NULL)
|
||||
#endif
|
||||
PHP_FE(stream_copy_to_stream, NULL)
|
||||
PHP_FE(stream_get_contents, NULL)
|
||||
PHP_FE(fgetcsv, NULL)
|
||||
|
|
|
@ -230,6 +230,17 @@ PHP_MINIT_FUNCTION(file)
|
|||
REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv23_SERVER", STREAM_CRYPTO_METHOD_SSLv23_SERVER, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLS_SERVER", STREAM_CRYPTO_METHOD_TLS_SERVER, CONST_CS|CONST_PERSISTENT);
|
||||
|
||||
REGISTER_LONG_CONSTANT("STREAM_SOCK_STREAM", SOCK_STREAM, CONST_CS|CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("STREAM_SOCK_DGRAM", SOCK_DGRAM, CONST_CS|CONST_PERSISTENT);
|
||||
#ifdef SOCK_RAW
|
||||
REGISTER_LONG_CONSTANT("STREAM_SOCK_RAW", SOCK_RAW, CONST_CS|CONST_PERSISTENT);
|
||||
#endif
|
||||
#ifdef SOCK_SEQPACKET
|
||||
REGISTER_LONG_CONSTANT("STREAM_SOCK_SEQPACKET", SOCK_SEQPACKET, CONST_CS|CONST_PERSISTENT);
|
||||
#endif
|
||||
#ifdef SOCK_RDM
|
||||
REGISTER_LONG_CONSTANT("STREAM_SOCK_RDM", SOCK_RDM, CONST_CS|CONST_PERSISTENT);
|
||||
#endif
|
||||
REGISTER_LONG_CONSTANT("STREAM_PEEK", STREAM_PEEK, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("STREAM_OOB", STREAM_OOB, CONST_CS | CONST_PERSISTENT);
|
||||
|
||||
|
|
|
@ -41,6 +41,38 @@ static php_stream_context *decode_context_param(zval *contextresource TSRMLS_DC)
|
|||
|
||||
/* Streams based network functions */
|
||||
|
||||
#if HAVE_SOCKETPAIR
|
||||
/* {{{ proto array stream_socket_pair(int domain, int type, int protocol)
|
||||
Creates a pair of indistinguishable socket streams */
|
||||
PHP_FUNCTION(stream_socket_pair)
|
||||
{
|
||||
long domain, type, protocol;
|
||||
php_stream *s1, *s2;
|
||||
zval *zs1, *sz2;
|
||||
int pair[2];
|
||||
|
||||
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",
|
||||
&domain, &type, &protocol)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (0 != socketpair(domain, type, protocol, pair)) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to create sockets: [%d]: %s",
|
||||
php_socket_errno(), php_socket_strerror(php_socket_errno()));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
array_init(return_value);
|
||||
|
||||
s1 = php_stream_sock_open_from_socket(pair[0], 0);
|
||||
s2 = php_stream_sock_open_from_socket(pair[1], 0);
|
||||
|
||||
add_next_index_zval(return_value, php_stream_get_resource_id(s1));
|
||||
add_next_index_zval(return_value, php_stream_get_resource_id(s2));
|
||||
}
|
||||
/* }}} */
|
||||
#endif
|
||||
|
||||
/* {{{ proto resource stream_socket_client(string remoteaddress [, long &errcode, string &errstring, double timeout, long flags, resource context])
|
||||
Open a client connection to a remote address */
|
||||
PHP_FUNCTION(stream_socket_client)
|
||||
|
|
|
@ -54,6 +54,7 @@ PHP_FUNCTION(stream_filter_prepend);
|
|||
PHP_FUNCTION(stream_filter_append);
|
||||
PHP_FUNCTION(stream_filter_remove);
|
||||
PHP_FUNCTION(stream_socket_enable_crypto);
|
||||
PHP_FUNCTION(stream_socket_pair);
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue