 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
roby65
Joined: 01 Jun 2008 Posts: 55 Location: Mid Italy
|
Posted: Sat Feb 13, 2010 1:20 am Post subject: Select() broken? |
|
|
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 |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Fri Feb 19, 2010 12:34 pm Post subject: |
|
|
| 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 |
|
 |
roby65
Joined: 01 Jun 2008 Posts: 55 Location: Mid Italy
|
Posted: Sat Feb 20, 2010 8:48 am Post subject: |
|
|
| 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 |
|
 |
|
|
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
|