forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FD_ISSET() code working on pc, but not on psp

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
cadaver



Joined: 07 Aug 2005
Posts: 21

PostPosted: Tue Sep 09, 2008 4:46 am    Post subject: FD_ISSET() code working on pc, but not on psp Reply with quote

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
View user's profile Send private message
cadaver



Joined: 07 Aug 2005
Posts: 21

PostPosted: Tue Sep 09, 2008 3:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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