in reply to Nonblocking read server

If you don't block or use async notifications you are "busy-waiting" and that's very bad: sucking up 100% of the CPU doing nothing. If your program's reason for existence is to read from any of one-or-more sockets and to write its output somewhere else, why not block? It becomes a classic "select()" scenario. After all, your program has nothing to do until the next message(s) come in.

Replies are listed 'Best First'.
Re^2: Nonblocking read server
by Carbonblack (Novice) on Sep 19, 2019 at 15:30 UTC
    Thank You very much for Your efford!

    I'll give it a try...

    Because system the script will run is an alix-hardware with openWrt it's quite hard to install fancy modules.

    Luckily select does not wait too busy if timeout is > 0.

    time perl Inet.Server6.pl 0 Active connections 0 Active connections real 1m1,987s user 0m0,023s sys 0m0,013s

    Well, if i play with this script and two instances ofcat - | nc -q 1 localhost 5000 the second line seems to vanish if the other instance is blocking the IO.
    I have no data-loss if the read-size is large enough and with non-blocking IO.