Re: Extension proposal: fdpass

From: Date: Wed, 27 Apr 2011 13:27:08 +0000
Subject: Re: Extension proposal: fdpass
References: 1 2 3  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-8191@lists.php.net to get a copy of this message
Okay, here's the patch ported to 5.3.6 dist .. it adds the function: resource socket_create_from_fdno(int fdno, int domain) for non-win32 systems .. Greetings Florian P.S. Should i make a new post @PHP-DEV list for this patch? Am 27.04.2011 14:12, schrieb Johannes Schlüter: > On Wed, 2011-04-27 at 13:13 +0200, Florian Wilkemeyer wrote: >> Hi Jille, >> >> i had the same requirements and i wrote a simple function and added it >> to the php sockets extension; >> to be able to create a 'php-socket' from a FD number (in my case my >> script gets forked from a webserver - which gives a acceptable pipe as >> fd#0 to the proc..) >> so it was possible to use the whole functionallity from php's socket >> extension.. > Might be a good idea. then one can figure out what the best approach for > this is, maybe it's worth adding the functionality to the core ... > >> If there's any interest i would provide the patch here, >> but its linux/unix based OS only.. no win32 :) > We don't limit PHP (especially PECL) to what's possible on a platform, > we try to unify were possible, while enabling system-specific things, > too :-) > > johannes >

diff -Naur php-5.3.6_dist/ext/sockets/php_sockets.h php-5.3.6_socketpatch/ext/sockets/php_sockets.h --- php-5.3.6_dist/ext/sockets/php_sockets.h 2011-01-01 03:19:59.000000000 +0100 +++ php-5.3.6_socketpatch/ext/sockets/php_sockets.h 2011-04-27 15:16:21.000000000 +0200 @@ -56,6 +56,9 @@ PHP_FUNCTION(socket_getsockname); PHP_FUNCTION(socket_getpeername); PHP_FUNCTION(socket_create); +#ifndef PHP_WIN32 +PHP_FUNCTION(socket_create_from_fdno); +#endif PHP_FUNCTION(socket_connect); PHP_FUNCTION(socket_strerror); PHP_FUNCTION(socket_bind); diff -Naur php-5.3.6_dist/ext/sockets/sockets.c php-5.3.6_socketpatch/ext/sockets/sockets.c --- php-5.3.6_dist/ext/sockets/sockets.c 2011-01-01 03:19:59.000000000 +0100 +++ php-5.3.6_socketpatch/ext/sockets/sockets.c 2011-04-27 15:19:53.000000000 +0200 @@ -177,6 +177,13 @@ ZEND_ARG_INFO(0, protocol) ZEND_END_ARG_INFO() +#ifndef PHP_WIN32 +ZEND_BEGIN_ARG_INFO_EX(arginfo_socket_create_from_fdno, 0, 0, 1) + ZEND_ARG_INFO(0, fdno) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() +#endif + ZEND_BEGIN_ARG_INFO_EX(arginfo_socket_connect, 0, 0, 2) ZEND_ARG_INFO(0, socket) ZEND_ARG_INFO(0, addr) @@ -269,6 +276,9 @@ PHP_FE(socket_select, arginfo_socket_select) PHP_FE(socket_create, arginfo_socket_create) PHP_FE(socket_create_listen, arginfo_socket_create_listen) +#ifndef PHP_WIN32 + PHP_FE(socket_create_from_fdno, arginfo_socket_create_from_fdno) +#endif #ifdef HAVE_SOCKETPAIR PHP_FE(socket_create_pair, arginfo_socket_create_pair) #endif @@ -1272,6 +1282,40 @@ } /* }}} */ +#ifndef PHP_WIN32 +/* {{{ proto resource socket_create_from_fdno(int fdno, int domain) + Creates an socket from given fd-number */ +PHP_FUNCTION(socket_create_from_fdno) +{ + long arg1, arg2; + php_socket *php_sock = NULL; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &arg1, &arg2) == FAILURE){ + return; + } + + if(arg2 != AF_UNIX +#if HAVE_IPV6 + && arg2 != AF_INET6 +#endif + && arg2 != AF_INET) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid socket domain [%ld] specified for argument 2, assuming AF_INET", arg2); + arg2 = AF_INET; + } + + + php_sock = (php_socket*)emalloc( sizeof(php_socket) ); + + php_sock->bsd_socket = arg1; + php_sock->type = arg2; + php_sock->error = 0; + php_sock->blocking = 1; + + ZEND_REGISTER_RESOURCE(return_value, php_sock, le_socket); +} +/* }}} */ +#endif + /* {{{ proto bool socket_connect(resource socket, string addr [, int port]) Opens a connection to addr:port on the socket specified by socket */ PHP_FUNCTION(socket_connect)
« previous php.pecl.dev (#8191) next »