Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - select() on UDP sockets: (8 Items)
   
select() on UDP sockets  
Hi,

If I call select() with a list of two sockets, select() always reports no data for each socket regardless of whether 
there is data in the socket. I know there is data because I can query the socket status via ioctl OSIFSKT_IOCTL_FIONREAD
 and both report true. I can also read the data from the sockets that I'd previously written to them. 

Does select work with non-blocking UDP sockets? 

Thanks much,
--Paul




Re: select() on UDP sockets  
On Thu, Aug 13, 2009 at 05:59:44PM -0400, Paul Kahn wrote:
> Hi,
> 
> If I call select() with a list of two sockets, select() always reports no data for each socket regardless of whether 
there is data in the socket. I know there is data because I can query the socket status via ioctl OSIFSKT_IOCTL_FIONREAD
 and both report true. I can also read the data from the sockets that I'd previously written to them. 
> 
> Does select work with non-blocking UDP sockets? 
> 

This seem to work for me.  Test cases attached.
If you're still having problems, please provide
a test.

Thanks,

-seanb
Attachment: Text tut3.c 1.87 KB Text tut4.c 1.16 KB
RE: select() on UDP sockets  
Works for me.

> -----Original Message-----
> From: Paul Kahn [mailto:community-noreply@qnx.com]
> Sent: Thursday, August 13, 2009 6:00 PM
> To: general-networking
> Subject: select() on UDP sockets
> 
> Hi,
> 
> If I call select() with a list of two sockets, select() always reports
> no data for each socket regardless of whether there is data in the
> socket. I know there is data because I can query the socket status via
> ioctl OSIFSKT_IOCTL_FIONREAD and both report true. I can also read the
> data from the sockets that I'd previously written to them.
> 
> Does select work with non-blocking UDP sockets?
> 
> Thanks much,
> --Paul
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> 
> General
> http://community.qnx.com/sf/go/post35963
> 
Re: RE: select() on UDP sockets  
Mario/Sean, thanks for your quick replies.

In some cases, we are using non-blocking sockets. If I modify the sockets in my test code so that they are blocking 
sockets this works, fine -- I missed that. I am trying to provide an API that takes a variable number of socket handles 
and waits (w/timeout) for any one of them to have data.

select() seemed perfect for this; but, apparently, only for blocking sockets. Am I doing something wrong or is that just
 the way select() works on QNX? 

Is there another way to do this? The socket list might be comprised of varying types of sockets (UDP/TCP) w/varying 
options set.
Re: RE: select() on UDP sockets  
On Fri, Aug 14, 2009 at 11:30:18AM -0400, Paul Kahn wrote:
> Mario/Sean, thanks for your quick replies.
> 
> In some cases, we are using non-blocking sockets. If I modify the sockets in my test code so that they are blocking 
sockets this works, fine -- I missed that. I am trying to provide an API that takes a variable number of socket handles 
and waits (w/timeout) for any one of them to have data.
> 
> select() seemed perfect for this; but, apparently, only for blocking sockets. Am I doing something wrong or is that 
just the way select() works on QNX? 
> 
> Is there another way to do this? The socket list might be comprised of varying types of sockets (UDP/TCP) w/varying 
options set.
> 

That should work fine.  The example I posted set nonblock.  If you
think there's a bug I'll need a test case.

Regards,

-seanb
Re: RE: select() on UDP sockets  
Problem was in my code: I am writing for multiple platforms and select() API differs slightly on Windows. I was passing 
in the number of socket handles to select() instead of the MAXIMUM handle value (of the set) plus 1.

Thanks for your help.
Re: RE: select() on UDP sockets  
> I am trying to provide an API that takes a variable number of socket 
> handles and waits (w/timeout) for any one of them to have data.
> 
> select() seemed perfect for this; but, apparently, only for blocking sockets. 
> Am I doing something wrong or is that just the way select() works on QNX? 
> 
> Is there another way to do this? The socket list might be comprised of varying
>  types of sockets (UDP/TCP) w/varying options set.

select() is a bad choice if you need to provide API for general case of any number of sockets. That's because the select
 uses a bitmask array with each bit corresponding to a socket FD value starting from zero to INT_MAX. Of course size of 
that array is limited by default while the value of FDs is not. And generally, you can't predict the size of array at 
compile time - you'll have to re-allocate bitmask in dynamic memory with size sufficient for the maximal value of socket
 FD you have and most of that memory will be just wasted. Also, it'll require scans through the array to find individual
 bits each time and the greater socket FD value the longer it'll need to scan even though there could just one FD passed
.
Consider changing to poll() while you have not wasted much time.
Re: RE: select() on UDP sockets  
Very good point, Oleh. I'll give that a try.

Thanks much.