|
27 | 27 | #include "php_ini.h"
|
28 | 28 | #include "ext/standard/info.h"
|
29 | 29 | #include "ext/session/php_session.h"
|
| 30 | +#include "ext/sockets/php_sockets.h" |
30 | 31 | #include "php_appserver.h"
|
31 | 32 | #include "TSRM.h"
|
32 | 33 | #include "SAPI.h"
|
@@ -59,6 +60,7 @@ const zend_function_entry appserver_functions[] = {
|
59 | 60 | PHP_FE(appserver_get_http_response_code, NULL)
|
60 | 61 | PHP_FE(appserver_get_envs, NULL)
|
61 | 62 | PHP_FE(appserver_session_init, NULL)
|
| 63 | + PHP_FE(appserver_stream_import_file_descriptor, NULL) |
62 | 64 | PHP_FE_END
|
63 | 65 | };
|
64 | 66 |
|
@@ -485,6 +487,28 @@ PHP_FUNCTION(appserver_set_headers_sent)
|
485 | 487 | SG(headers_sent) = headers_sent_flag;
|
486 | 488 | }
|
487 | 489 |
|
| 490 | +/* {{{ proto array appserver_stream_import_file_descriptor(resource $socket) |
| 491 | + will return the file descriptor as int of a php stream resource ... /* }}} */ |
| 492 | +PHP_FUNCTION(appserver_stream_import_file_descriptor) |
| 493 | +{ |
| 494 | + zval *zstream; |
| 495 | + php_stream *stream; |
| 496 | + PHP_SOCKET socket; /* fd */ |
| 497 | + |
| 498 | + /* parse params and get stream resources passed to function */ |
| 499 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) == FAILURE) { |
| 500 | + return; |
| 501 | + } |
| 502 | + /* get stream from given php userland zval */ |
| 503 | + php_stream_from_zval(stream, &zstream); |
| 504 | + /* check if stream can be casted to a socket fd */ |
| 505 | + if (php_stream_cast(stream, PHP_STREAM_AS_SOCKETD, (void**)&socket, 1)) { |
| 506 | + /* return a negative long to declair a non existent fd */ |
| 507 | + RETURN_LONG(-1); |
| 508 | + } |
| 509 | + /* finally return the fd as long to userland*/ |
| 510 | + RETURN_LONG(socket) |
| 511 | +} |
488 | 512 |
|
489 | 513 | // ---------------------------------------------------------------------------
|
490 | 514 | // Zend Extension Functions
|
|
0 commit comments