Jump to content
  • Advertisement
Sign in to follow this  
Tera_Dragon

select fails

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got an FD_SET to hold all of my client sockets, but when I call select it fails. Do you have any idea what could cause this? I don't think I'm doind anything out of the ordinary. Tera_Dragon

Share this post


Link to post
Share on other sites
Advertisement
By fails I mean that it returns SOCKET_ERROR.
As for code, I'm not really sure about what to give so here's the call to select and a bit more:


WaitForSingleObject(mutexHandle, INFINITE);

tempSet = masterSet;

ReleaseMutex(mutexHandle);

if(tempSet.fd_count == 0)
{
return true;//NULL;
}

timeval waitTime;
waitTime.tv_sec = 0;
waitTime.tv_usec = 0;

error = select(tempSet.fd_count, &tempSet, NULL, NULL, &waitTime);

if( error == SOCKET_ERROR)
{
cout << "Error in select\n";
Shutdown();
return false;
}



Hope that this makes more sense

Share this post


Link to post
Share on other sites
Call WSAGetLastError() to get the error code of what went wrong, then look up that error code on MSDN to find out exactly what is wrong.

You did call WSAStartup(), didn't you?

Share this post


Link to post
Share on other sites
I've checked to see if it is empty, and if so then miss the select. But I just called Sleep for 10 seconds, long enough for me to get a clientto connect, and all was fine....

Edit: just found out that the error message was only delayed...duh

Share this post


Link to post
Share on other sites
The error code is 10038, WSAENOTSOCK. This means that I tried to perform a socket operation on something that is not a socket, or a member of my fd_set is not vaild when I pass it to the select function.
I still have no idea. Everything looks ok. But just incase that I am not setting the client sockets correctly here is my client acceptance code:


DWORD WINAPI NetworkServer::acceptingProcedure_Static(LPVOID lpParameter)
{
((NetworkServer*)lpParameter)->acceptingProcedure();
return 0;
}

void NetworkServer::acceptingProcedure()
{
for(;;) // run forever
{
if( unsigned int clientSocket = accept(mySocket, 0, 0) == SOCKET_ERROR)
{
//MessageBox(NULL, "Accept failed.", "Error", NULL);
cout << "Accept failed";
quitFlag = true;
return;
}
else
{
cout << "Client connected\n";
WaitForSingleObject(mutexHandle, INFINITE);

FD_SET(clientSocket, &masterSet);

ReleaseMutex(mutexHandle);
}
}
}



Tera_Dragon

Share this post


Link to post
Share on other sites
Instead of doing your own socket implementation..find an existing one..look at codeproject or something.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!