EvIo::$fd wrong resource

Issue #25 wontfix
Alex Sky created an issue
<?php

echo STDIN."\n"; // Resource id #1

$io = new EvIo(STDIN, Ev::READ | Ev::WRITE, function ($w) {

    echo $w->fd."\n"; // Resource id #4

    $w->stop();
    Ev::stop();
});

Ev::run();

Comments (6)

  1. Ruslan Osmanov repo owner

    Why do you think it is wrong? A file descriptor can be wrapped into multiple resources. It doesn't mean that the wrapped value changes.

  2. Alex Sky reporter
    <?php
    
    $socket = stream_socket_server('tcp://0.0.0.0:8080');
    
    $io = new EvIo($socket, Ev::READ, function ($w) use($socket) {
    
        $fd = stream_socket_accept($w->fd); // $fd = FALSE
        // PHP Warning:  stream_socket_accept(): accept failed: Unknown error
    
        $fd = stream_socket_accept($socket); // $fd = Resource id #6
        // OK
    });
    
    Ev::run();
    
    fclose($socket);
    
  3. Ruslan Osmanov repo owner
        $fd = stream_socket_accept($w->fd); // $fd = FALSE
    

    FALSE? Really? I think it's rather something like this:

    resource(6) of type (stream)
    
    Warning: stream_socket_accept(): accept failed: Unknown error in /home/ruslan/projects/pecl/ev/1.php on line 8
    

    (the output in my terminal when I try to connect to 127.0.0.55:8080.

    Still we've got an error from stream_socket_accept which tried to work with the stream passed to the callback. The problem is that the Ev extension didn't promise to pass stream of specific type into the user callback. It's just a wrapper for a numeric file descriptor which is scarcely useful with the most PHP stream functions.

    The Ev extension doesn't store information about the input stream types. So it doesn't even try to reconstruct the same kinds of stream resources for the user callbacks.

    So this is actually by design. The stream is supposed to be passed around the Ev API, and similar things.

  4. Log in to comment