Re: Is it correct to store poll() file descriptors in the extension globals?
| From: | Ruslan Osmanov | Date: | Sat, 17 Sep 2011 06:28:26 +0000 |
| Subject: | Re: Is it correct to store poll() file descriptors in the extension globals? | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-8540@lists.php.net to get a copy of this message | ||
I made some tests in PHP-FPM. It seems, MINIT is called for each eio_* call,
i.e. for each PECL function call. Thus, extension globals are not suitable,
at least for PHP-FPM.
I'm thinking of storing the structure instance with descriptors in
EG(persistent_list) scope. Should I destroy it in GSHUTDOWN, MSHUTDOWN, or
RSHUTDOWN?
Ruslan Osmanov wrote:
>
> Hello.
>
> I need help.
>
> I'm writing a wrapper for libeio C library as a PECL extension. I want
> user to invoke event loop function after a bunch of libeio calls:
> <?php
> eio_mkdir("my-eio-test-dir", 0750, 0, "my_mkdir_done", "custom
> data!");
> eio_nop(0, "my_nop_done", "nop");
> eio_rmdir("my-eio-test-dir", 0, "my_rmdir_done", "rm dir done");
> eio_event_loop(); // <------------------------
> ?>
>
> In C it looks like the following:
>
> static PHP_GINIT_FUNCTION(eio)
> {
> eio_globals->respipe[0] = eio_globals->respipe[1] = 0;
> }
> PHP_MINIT_FUNCTION(eio)
> {
> // ...
> if (pipe(EIO_G(respipe))) {
> php_error_docref(NULL TSRMLS_CC, E_ERROR, "failed creating
> pipe, errno: '%d'", errno);
> return FAILURE;
> }
>
> if (eio_init(php_eio_want_poll_callback,
> php_eio_done_poll_callback) != 0) {
> php_error_docref(NULL TSRMLS_CC, E_ERROR, "failed initializing
> eio, errno: '%d'", errno);
> return FAILURE;
> }
>
> return SUCCESS;
> }
>
> static void
> php_eio_want_poll_callback(void)
> {
> char dummy;
> TSRMLS_FETCH();
>
> write (EIO_G(respipe[1]), &dummy, 1);
> }
>
> static void
> php_eio_done_poll_callback(void)
> {
> char dummy;
> TSRMLS_FETCH();
>
> read (EIO_G(respipe[0]), &dummy, 1);
> }
>
> PHP_FUNCTION(eio_event_loop)
> {
> struct pollfd pfd;
> pfd.fd = EIO_G(respipe [0]);
> pfd.events = POLLIN;
>
> while (eio_nreqs())
> {
> eio_poll();
> poll(&pfd, 1, -1);
> }
> }
>
> Since eio_ functions are asynchronous, I'm concerned about thread safety
> of the respipe global.
> I'm new to PECL. Please, give me a tip, how should I keep the file
> descriptors.
>
> --
> PECL development discussion Mailing List (http://pecl.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> -----
> Regards,
>
> Ruslan Osmanov
>
> Mobile: +998739502399
> Blog: http://osmanov-dev-notes.blogspot.com/
> Twitter: @ruslan_osmanov
>
-----
Regards,
Ruslan Osmanov
Mobile: +998739502399
Blog: http://osmanov-dev-notes.blogspot.com/
Twitter: @ruslan_osmanov
--
View this message in context: http://old.nabble.com/Is-it-correct-to-store-poll%28%29-file-descriptors-in-the-extension-globals--tp32480673p32483487.html
Sent from the Pecl - Dev mailing list archive at Nabble.com.