 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
cadaver
Joined: 07 Aug 2005 Posts: 21
|
Posted: Tue Sep 09, 2008 4:46 am Post subject: FD_ISSET() code working on pc, but not on psp |
|
|
| Code: |
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;
}
|
This code is working as it should on the pc. (there is only one socket fd in the master set, I'm listening to)
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); |
|
| Back to top |
|
 |
cadaver
Joined: 07 Aug 2005 Posts: 21
|
Posted: Tue Sep 09, 2008 3:31 pm Post subject: |
|
|
Seems, select/FD_ISSET don't work with dgram sockets (psp)?
I've set the socket now to nonblock (fcntl(fd_dgram_listen, F_SETFL, O_NONBLOCK);) and I'm repeating recvfrom while nbytes > 0. Then it's ok. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|