Is it correct to store poll() file descriptors in the extension globals?

From: Date: Fri, 16 Sep 2011 17:23:58 +0000
Subject: Is it correct to store poll() file descriptors in the extension globals?
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-8539@lists.php.net to get a copy of this message
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.

« previous php.pecl.dev (#8539) next »