Archived

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

Help about "select"-Why I always got 10022 error?

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

Recommended Posts

Expect for the first message which I get correctly, it no longer get any messages. When I checked it with breakpoint, first cycle was ok,then the "ret" was 0, and in the third cycle the result was SOCKET_ERROR and WSAGetLastError returned 10022(WSAEINVAL). I put these code in a single thread.When I comment all the other statements and it seems like below,nothing help. Thanks for you help! ////////////////////////////////////////////////////////// FD_ZERO(&fdread); FD_SET(c_socket,&fdread); tval.tv_usec = 0; tval.tv_sec = 1; while(true) { ret = select(0,&fdread,NULL,NULL,&tval); if(ret == 0 || ret == SOCKET_ERROR) { ret = WSAGetLastError(); continue; } ret = recv(c_socket,buf_char,BUFFERSIZE,0); }

Share on other sites
If you read the documentation for select(), you''d have noticed that select() changes the fd_sets you pass as parameters (and this is a necessary feature...).

This means you have to rebuild the fd_sets every time before calling select().

cu,
Prefect

Share on other sites
select() is IMHO the winner of the most poorly design api ever award. It''s extremly hard to use correctly. As Prefect says, the fd_set is not reusable. Rebuild the whole thing every time.

It gets worse if you''re trying to make portable code and need to set the nfds parameter.

Share on other sites
quote:
Original post by Anon Mike
select() is IMHO the winner of the most poorly design api ever award. It''s extremly hard to use correctly. As Prefect says, the fd_set is not reusable. Rebuild the whole thing every time.

Not neccessarily =)

Just keep two sets like this:

  fd_set fullset;fd_set tempset;// fill out fullsetwhile( networkloop ){    tempset = fullset;    select( 0, &tempset, 0, 0, 0 );}

Share on other sites
I concur that select() has to be one of the most poorly designed functions I''ve seen in any API.

Share on other sites
Great thanks for all of you with your kind advices! I''ll try a
so late. I''ll never forget to check the "Notice Me" title again.