From: Matteo Nastasi (mop) Date: Tue, 19 Jun 2012 05:37:04 +0000 (+0200) Subject: first working version (one shot version) X-Git-Tag: v0.2.0~2 X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=d01d2155a49053f403e038b05ff7623d8efd3ea7;p=php-ancillary.git first working version (one shot version) --- diff --git a/php-ancillary.c b/php-ancillary.c index be249c9..115221a 100644 --- a/php-ancillary.c +++ b/php-ancillary.c @@ -2,6 +2,7 @@ #include "config.h" #endif #include "php.h" +#include #define PHP_ANCILLARY_VERSION "1.0" #define PHP_ANCILLARY_EXTNAME "ancillary" @@ -10,12 +11,12 @@ extern zend_module_entry ancillary_module_entry; #define phpext_ancillary_ptr &ancillary_module_entry // declaration of a custom mop_function() -PHP_FUNCTION(mop_function); +PHP_FUNCTION(ancillary_getstream); // list of custom PHP functions provided by this extension // set {NULL, NULL, NULL} as the last record to mark the end of list -static function_entry mop_functions[] = { - PHP_FE(mop_function, NULL) +static function_entry ancillary_getstream[] = { + PHP_FE(ancillary_getstream, NULL) {NULL, NULL, NULL} }; @@ -25,7 +26,7 @@ zend_module_entry ancillary_module_entry = { STANDARD_MODULE_HEADER, #endif PHP_ANCILLARY_EXTNAME, - mop_functions, + ancillary_getstream, NULL, // name of the MINIT function or NULL if not applicable NULL, // name of the MSHUTDOWN function or NULL if not applicable NULL, // name of the RINIT function or NULL if not applicable @@ -39,8 +40,30 @@ zend_module_entry ancillary_module_entry = { ZEND_GET_MODULE(ancillary) -// implementation of a custom mop_function() -PHP_FUNCTION(mop_function) +// starting from a unix socket receive a socket from an external process +PHP_FUNCTION(ancillary_getstream) { - RETURN_STRING("This is my function", 1); + zval *zstream; + php_stream *stream; + int fd_in, fd_out; + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream)) + return; + + php_stream_from_zval(stream, &zstream); + + if (php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fd_in, REPORT_ERRORS) == FAILURE) { + RETURN_FALSE; + } + + if(ancil_recv_fd(fd_in, &fd_out)) { + RETURN_FALSE; + } + + if ((stream = php_stream_fopen_from_fd(fd_out, "r+b", NULL)) == NULL) { + RETURN_FALSE; + } + + php_stream_to_zval(stream, return_value); } + diff --git a/test001.php b/test001.php new file mode 100755 index 0000000..fd2e1f4 --- /dev/null +++ b/test001.php @@ -0,0 +1,31 @@ +#!/usr/bin/php + \ No newline at end of file