Cross-platform (linux/Win32) nonblocking C++ IO on stdin/stdout/stderr

前端 未结 3 1754
南笙
南笙 2021-02-14 12:14

I\'m trying to find the best solution for nonblocking IO via stdin/stdout with the following characteristics:

  • As long as there is enough data, read in n-s
3条回答
  •  天涯浪人
    2021-02-14 12:55

    I did something similar to jwhitlock ... I ended up with a StdinDataIO class that wraps around the appropriate OS-specific implementation(*) so that the rest of my program can select() on the file descriptor StdinDataIO provides, remaining blissfully ignorant of Windows' limitations regarding stdin. Have a look here and here if you like, the code is all open-source/BSD-licensed.

    (*) the implementation is a simple pass-through for Linux/MacOSX, and in Windows it's a rather complex process of setting up a child thread to read from stdin and send the data it receives over a socket back to the main thread... not very elegant, but it works.

提交回复
热议问题