Code: Select all
bool getServerMessagesDgram()
{
begin:
read_fds = master;
timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 0;
if (select(FD_SETSIZE, &read_fds, NULL, NULL, &tv) == -1)
{
report_error("select failed.");
return false;
}
if (FD_ISSET(fd_dgram_listen, &read_fds))
{
char buf[MESSAGE_LENGTH_SERVER];
sockaddr_in remoteaddr;
socklen_t addrlen;
addrlen = sizeof remoteaddr;
int nbytes = recvfrom(fd_dgram_listen, buf, MESSAGE_LENGTH_SERVER, 0, (sockaddr*)&remoteaddr, &addrlen);
if (nbytes > 0)
{
// do something useful...
goto begin; // read all from buffer...
}
return true;
}
return false;
}
But on the psp, FD_ISSET is always true, so the function loops forever, and recvfrom forever recieves bytes of length "MESSAGE_LENGTH_SERVER".
Both sets were cleared with
FD_ZERO(&master);
FD_ZERO(&read_fds);
The master was set up with
FD_SET(fd_dgram_listen, &master);