Jump to content
  • Advertisement
Sign in to follow this  
Muppi

Runtime problems with my server, help!

This topic is 5412 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

Ello everybody. Ive made a server from the nonblocking server tutorial, and my clients are stored in a double linked list but its giving me problems at runtime, this piece of code is the core of the evil.
void O3VServerNetwork::Check_Message()
{
	fd_set input_set, exc_set;
	int s, nfds;
	timeout.tv_sec = 0;
	timeout.tv_usec = 0;

	FD_ZERO(&input_set);
	FD_ZERO(&exc_set);
	nfds = 0;

	Clients *loopTemp1 = head;
	while(loopTemp1 != NULL)
	{
		FD_SET(loopTemp1->clientSocket, &input_set);
		FD_SET(loopTemp1->clientSocket, &exc_set);
		nfds++;
		loopTemp1 = loopTemp1->Next;
	}
	s = select(nfds, &input_set, NULL, &exc_set,&timeout);
	if(s > 0)
	{
		Clients *temp = head; 
		while(temp != NULL)    // my troubles start here!
		{  
 			if(FD_ISSET(temp->clientSocket, &exc_set))
			{
				DisClient(temp->ID);
			}
			if(FD_ISSET(temp->clientSocket, &input_set))
			{
				Get_Msg(temp->ID);
			}
			temp = temp->Next;
		} 
	}
}

i know you dont have allot to work with but if you have any suggestions on what might be wrong.. please help cause this is driving me insane!

Share this post


Link to post
Share on other sites
Advertisement
hi muppi,

the first parameter of select() is not the number of the descriptors, but the HIGHEST descriptor (+ 1) of the sets!

so you have to rewrite your loops:


maxfds=0
while(loopTemp1 != NULL)
{
FD_SET(loopTemp1->clientSocket, &input_set);
FD_SET(loopTemp1->clientSocket, &exc_set);

// this one is new
if (loopTemp1->clientSocket>maxfds) maxfds=loopTemp1->clientSocket;

loopTemp1 = loopTemp1->Next;
}

// now call select
s=select(maxfds+1, ...) // note the +1!



hth,
chris

Share this post


Link to post
Share on other sites
Although the first parameter for select() is ignored by the windows implementation (Its still good practice to have it valid though, for portability).
What do you mean by its giving you "problems at runtime"? What sort of problems? Does it crash? If so, whats the error? Access violation? Have you tried using the debugger to see if theres anything unusual?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!