7

Coming from a linux background, I'm used to the concept that everything is a file, i.e. sockets AND stdin.

This makes it easy to write a simple server/client using select(), where I include STDIN in the fdset so it'll allow me to use the terminal for input, especially for debugging.

Moving to windows however, the concept of "everything is a file" does not hold anymore. using select() for stdin (even after defining STDIN_FILENO as 0) simply doesn't work.

What's the best way to port a code using select() (for both stdin and actual sockets) to work on windows?

netanelw
  • 121
  • 1
  • 4

1 Answers1

3

You really answered the question (in part) already. The rules for sockets on Windows and Linux are similar (as far as concept) but not exactly the same.

Here is a link that discusses porting Windows to Linux.

And here is one porting Linux to Windows. (read the links in the bottom post.)

ryyker
  • 22,849
  • 3
  • 43
  • 87
  • neither of these mentions using select for stdin? – Tim Oct 13 '19 at 00:58
  • 1
    @TimBaker - _[select](https://tangentsoft.net/wskfaq/articles/bsd-compatibility.html)_ is mentioned in both the first _and_ second link I provided. ( via this site: https://tangentsoft.net/wskfaq/articles/bsd-compatibility.html ) Thanks. – ryyker Oct 13 '19 at 23:50
  • :o sorry about that. I missed it! thank you! it's listed under poll. – Tim Oct 14 '19 at 04:57
  • 1
    @Tim - No problem. If you are the recent down-voter, does my comment satisfy the reason so that you can retract your down-vote? Thanks. – ryyker Oct 14 '19 at 12:00
  • 1
    Thanks for the help @ryyker, I didn't realize I had down voted that, since the links were helpful. – Tim Nov 05 '19 at 05:48
  • Hi Ryyker, I'm having EXACTLY this question but you supply two links that in turn link to many other pages that link to other pages. I cannot find mention of using stdin's fileno with select on WIN32. Can you specifically answer that question? – Swiss Frank Feb 15 '23 at 20:41
  • 1
    @SwissFrank - Windows does not use fileno, it rather uses handles as a way to reference an established socket. Did you happen to look at the link provided to a similar question in the 2nd comment? It contains [this link](https://tangentsoft.com/wskfaq/advanced.html#64sockets) for focused discussion on sockets, include use of _select_. Beyond that, it may be best for you to post a separate question and include the specifics of what you need there. – ryyker Feb 16 '23 at 13:42