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 

Select() broken?

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



Joined: 01 Jun 2008
Posts: 55
Location: Mid Italy

PostPosted: Sat Feb 13, 2010 1:20 am    Post subject: Select() broken? Reply with quote

Hi guys,
can someone confirm me that select() is broken?

I use it for testing if a socket is ready to send and receive, and it always tell me that the socket is ready for reading and writing also if it is not.

code:
Code:

#define POLLIN 1
#define POLLOUT 2
#define POLLERR 4
#define POLLHUP POLLERR
#define POLLPRI 8
#define POLLNVAL POLLERR

struct pollfd
{
   int fd;
   unsigned char events;      //What events to capture
   unsigned char revents;      //Events captured
};

int poll(struct pollfd* socklist,int count, int unk)
{
   fd_set read_flags,write_flags;
   int i=0,ret;
   struct timeval waitd;
   int maxfd=0;
   waitd.tv_sec = 0;
   waitd.tv_usec = 5;
   FD_ZERO(&read_flags);
   FD_ZERO(&write_flags);

   for (i=0;i<count;i++)
   {
      if((socklist[i]->fd)<0)
         continue;
      if(socklist[i]->events & POLLIN)
         FD_SET(socklist[i]->fd, &read_flags);
      if(socklist[i]->events & POLLOUT)
         FD_SET(socklist[i]->fd, &write_flags);
         
      if ((socklist[i]->fd)>maxfd)
      {
         maxfd=socklist[i]->fd;
      }
         
   }
   ret=select((maxfd)+1, &read_flags,&write_flags,(fd_set*)0,&waitv);
   if(ret<0)
   {
      //Error handling
   }
   
   for (i=0;i<count;i++)
   {
      if((socklist[i]->fd)<0)
         continue;
      if(socklist[i]->events & POLLIN)
         if(FD_ISSET(socklist[i]->fd,&read_flags))
         {
            socklist[i]->revents |=POLLIN;
         }
      if(socklist[i]->events & POLLOUT)
         if(FD_ISSET(socklist[i]->fd,&write_flags))
         {
            socklist[i]->revents |=POLLOUT;
         }
   }   
   return 1;
   
}
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Fri Feb 19, 2010 12:34 pm    Post subject: Reply with quote

What's ret? If it's zero due to timeout (yours is extremely short), maybe the fd_sets aren't being cleared. You can try also try drilling down into newlib's libc/sys/psp/select.c to see where they're getting set.
Back to top
View user's profile Send private message
roby65



Joined: 01 Jun 2008
Posts: 55
Location: Mid Italy

PostPosted: Sat Feb 20, 2010 8:48 am    Post subject: Reply with quote

jimparis wrote:
What's ret? If it's zero due to timeout (yours is extremely short), maybe the fd_sets aren't being cleared. You can try also try drilling down into newlib's libc/sys/psp/select.c to see where they're getting set.

That's the problem, i must check if ret is 0 due to timeout, thanks! :)
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
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