Advertisement

new weird bug ....

Started by June 19, 2002 11:16 PM
5 comments, last by CoMaNdore 22 years, 7 months ago
why wont this code alow a client to join ?

void CServer::GetClients()
{
	fd_set data;

	FD_ZERO(&data);
	FD_SET(this->LSocket,&data);

	int s;
	s = select(NULL,&data,NULL,NULL,&timeout);

	while(s > 0)
	{          //this is hardcoded and will be changed later
		client[0].Get = accept(LSocket,NULL,NULL);
		break;

	}

}
 
yes i am looping it
- Me
Umm... that while()-loop doesn''t really make sense (ever heard of "if"? ). Apart from that: did you read the select() manual page? The first parameter to select() is supposed to be the highest numbered fd; in your case, it''s LSocket+1.

What is timeout? Since timeout is probably going to be destroyed by select() (I''m not sure what it''s supposed to do, but I wouldn''t bet on anything), you should explicitly set timeout to a reasonable value before calling select().

Oh, and you did call listen() on the LSocket, right?

cu,
Prefect

Return to the Shadows
Widelands - laid back, free software strategy
Advertisement
fist of thw while loop is a part of somthing bigger i made.
and this is what msdn says bout parameter 1:
[in] Ignored. The nfds parameter is included only for compatibility with Berkeley sockets.

yes i am calling listning and binding on my LSocket

btw wath do i set the timeout values to ?
i set both tv_usec & tv_sec to 0;

[edited by - CoMaNdore on June 20, 2002 8:30:55 AM]
- Me
It''s the number of seconds and micro (not milli) seconds that select will wait for a change in state of one of the FD''s before it returns. If you set it to 0, 0 it is effectively non-blocking. If you pass NULL instead of a timeval structure, it will block until soemthing happens.
You are calling GetClient in a loop yes? If not you are probably not getting any connections because select() is returning immediately before anything has happened.
The first parameter of select is ignored in winsock. He probably did read the docs.

As an aside the whole nfds parameter thing has got to be the worst design decision in the history of sockets. Talk about catering to the implementer''s needs over the customers. Sheesh.

-Mike
-Mike
So the code is all clean ?
HOW THE FUCK CAN THAT BE !!
(are i suposed to do anything specsial since i am using none blocking and not blocking. / exept from the code i got over there ..)
- Me
Advertisement
try re-writing the code in a simple test app (no classes, just plain old procedural) to make sure the code works. if it does then there is probably a problem somewhere else in your CServer class maybe.

This topic is closed to new replies.

Advertisement