Runtime problems with my server, help!

Started by
1 comment, last by Evil Steve 19 years, 7 months ago
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!
Things i felt yesterday, don''t matter any more.
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=0while(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 selects=select(maxfds+1, ...) // note the +1!


hth,
chris
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?

This topic is closed to new replies.

Advertisement