in reply to Re^5: How to make sysread timeout
in thread How to make sysread timeout

Unfortunately, the tutorial is pretty much useless for a win32 user as

  1. select doesn't work on file-handles under win32.

    I've also wondered what happens (under *nix) if you call can_read() on a file handle connected to a file that is being written to by another process (as when tailing a file), if some new data has been written (and could therefore be read), but not enough has been written to satisfy the number of characters requested in the sysread?

    Does sysread return immediately with just that number of characters as are available, or does it block indefinitely waiting until it can satisfy the full read request?

  2. The discussion is incomplete with respect to using select on sockets, as it does not discuss blocking. Specifically setting sockets non-blocking.

    Again, if a (blocking) socket has received some data before the timeout, but not enough to satisfy the number specified on the sysread, can_read() will have returned true, but will sysread block or not?

    It's also the case that using the blocking => 1 parameter to IO::Socket->new() also does not work under win32. Whilst it is possible to set Win32 sockets non-blocking, and the means is discussed here at PM, the details are somewhat shrouded in mystery and are not discussed or even mentioned in any of the Perl docs.


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^7: How to make sysread timeout
by erroneousBollock (Curate) on Nov 02, 2007 at 12:22 UTC
    Again, if a (blocking) socket has received some data before the timeout, but not enough to satisfy the number specified on the sysread, can_read() will have returned true, but will sysread block or not?
    I'd have thought that it's obvious that sysread blocks if there's no data, but otherwise returns the number of bytes actually read.

    Those Win32 issues sound nasty. I have three questions:

    • Are all those problems documented somewhere?
    • Are there any modules which mitigate that situation?
    • If so, is there any reason why IO::Select, IO::Handle, etc can't be told to use them?

    -David

      I'd have thought that it's obvious that sysread blocks if there's no data, but otherwise returns the number of bytes actually read.

      Why is that obvious? It isn't mentioned under sysread, or select or in thePOD of IO::Select.

      Are all those problems documented somewhere?

      Depends what you call 'documented'?

      Not that I'm aware of in the Perl documentation beyond perhaps some oblique comments regarding 'legacy' or 'dosish' systems.

      The first discussion here at PM that I am aware of, and the basis of whatever I have discovered is Non blocking socket open. For a more complete list of the posts that mention the problems you could try google

      Are there any modules which mitigate that situation?

      None that I am aware of.

      If so, is there any reason why IO::Select, IO::Handle, etc can't be told to use them?

      See (tye)Re: Non blocking socket open


      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.