Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7048889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:56:46+00:00 2026-05-28T02:56:46+00:00

Using Winsock2 the code sequence below returns -1 (failure) for select() . #include <Winsock2.h>

  • 0

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

#include <Winsock2.h>
#include <stdio.h>

...

int rc;
int fdstdin = fileno(stdin); /* returns 0 as expected */
fd_set fds;

FD_ZERO(&fds);
FD_SET(fdstdin, &fds);

rc = select(1, &fds, NULL, NULL, NULL);

...

Is this the expected behaviour when using Winsock2 or am I missing something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:56:46+00:00Added an answer on May 28, 2026 at 2:56 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have this source: #include <winsock2.h> #include <windows.h> #include <iostream> #pragma comment(lib,"ws2_32.lib") using
I am creating a winsock UDP program. code i am using is shown below.
I`m writing a chat using WinSock2 and WinAPI functions. And I have a little
I'm updating legacy code written in VB6 using Winsock controls. Essentially, I'm trying to
When using std::codecvt 's in method to decode an external byte sequence to an
I want to use an older code-fragment in my Qt-project, which is using WinSocks.
I'm using the code from MSDN's recv() page , but I changed the data
I have a c++ program using winsock2. I would like to know how to
I am trying to make a program using Winsock2 where I can send a
I have made a chat program with using Winsock2.h and the lib file ws2_32.lib.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.