Winsock2's select() on fd 0 (stdin) fails

后端 未结 1 1157
春和景丽
春和景丽 2020-12-22 07:14

Using Winsock2 the code sequence below returns -1 (failure) for select().

#include 
#include 

        
相关标签:
1条回答
  • 2020-12-22 07:22

    This is expected behavior. As mentioned all over the documentation, winsock's select function only works on sockets, and stdin is not a socket.

    If you had called WSAGetLastError, you undoubtedly would have found that the cause was

    WSAENOTSOCK One of the descriptor sets contains an entry that is not a socket.

    Try WSAEventSelect and WaitForMultipleObjectsEx; the latter can also wait on normal file handles as well as OVERLAPPED event objects from outstanding read operations on normal file handles.

    0 讨论(0)
提交回复
热议问题