#### Archived

This topic is now archived and is closed to further replies.

# select giving me a WSAEINVAL error...

This topic is 5398 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i am getting a WSAEINVAL error from the "select()" function. the documentation says this error means "The timeout value is not valid, or all three descriptor parameters were NULL." i am quite certain that all three descriptor parameters are not NULL (and yes, i do rebuild them each time), nor is the timeout value invalid (it is set to {0,0} for polling, as per the documentation, and i even tried to replace it with NULL (blocking) just to see if it worked). strangely enough, it works in another program i wrote a while back, which i re-compiled just to make sure this is very frustrating, can anyone think of something that might be wrong? here is the relevant code:
  timeval timeout;
fd_set input_set, exc_set;
int s, nfds;
FD_ZERO(&input_set);
FD_ZERO(&exc_set);
nfds = 0;
timeout.tv_sec = 0;
timeout.tv_usec = 0;
for(int i = 0; i < MAX_CLIENTS; ++nfds, ++i)
{
if(p_clients[i].checkStatus(CSTATUS_ACTIVE))
{
FD_SET(p_clients[i].getSocket(), &input_set);
FD_SET(p_clients[i].getSocket(), &exc_set);
};
};
s = select(nfds, &input_set, 0, &exc_set, &timeout);

p_clients is an array of my "client connection class", which basically holds a SOCKET and a status (checkStatus(CSTATUS_ACTIVE) returns true if there is an open socket there). at the point directly after the last line above, s == SOCKET_ERROR, and WSAGetLastError() returns the WSAEINVAL. thanks in advance!

##### Share on other sites
ok, after some more testing, i discovered that i only get this error when there is nobody connected (i.e. the "input_set" and "exc_set" are empty). once there is even a single socket in the list i do not get the error. i suppose i could ignore the error if there is nobody connected at all (in fact, i might as well skip the "select" altogether), but it still bugs me that this error occurs when it shouldn''t (i.e. none of the parameters are invalid, they''re just empty).

strangely enough, the older program i mentioned still works fine when nobody is connected.

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633395
• Total Posts
3011653
• ### Who's Online (See full list)

There are no registered users currently online

×