in reply to [Win32] IO::Select's can_read method

select (and IO::Select) only work on Sockets, not on pipes or filehandles on Windows.

As far as I have seen, it is not easy to conveniently retrofit select onto Windows filehandles, because asynchronous Windows IO seems mostly to be done using IO Completion Ports. These allow you to asynchronously read in data, but they don't allow you to check whether there actually is data available to be read. The same problem occurs when using threads.

Replies are listed 'Best First'.
Re^2: [Win32] IO::Select's can_read method
by syphilis (Archbishop) on Dec 09, 2011 at 09:42 UTC
    select (and IO::Select) only work on Sockets, not on pipes or filehandles on Windows

    Which reminds me that, while the demo portrays the problem using a filehandle, in the real-world app we're dealing with pipes. (To that extent, it was a bad demo).

    For filehandles perhaps we can query the list returned by the IO::Select handles method to see if they're readable (using Win32::Fmode or Filehandle::Fmode) ... would that emulate the work of the can_read method (if it's even feasible) ?

    But then, like I've just said, in actuality they're *pipes* not filehandles ...

    Cheers,
    Rob

      Unix select behaviour for pipes could be emulated on Win32 using PeekNamedPipe().

      Although the function name suggests that this is design for use with named pipes, it also works with anonymous pipes:

      hNamedPipe in

      A handle to the pipe. This parameter can be a handle to a named pipe instance, as returned by the CreateNamedPipe or CreateFile function, or it can be a handle to the read end of an anonymous pipe, as returned by the CreatePipe function. The handle must have GENERIC_READ access to the pipe.

      Similarly, can_read() could be implemented for files using Alertable IO, and callbacks placed on the Asynchronous Procedure Queue.

      Implementing either would require a substantial rewrite of win32_select() in win32sck.c


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        The ugly part of Alertable IO is that you will always read (at least) one byte that you can't easily stuff back. I haven't found (by just reading the documentation, not by trying it out) a way that gives you just "you can read n bytes from this filehandle now" or "read as many bytes as are available without blocking" outside of PeekNamedPipe().