Sean Boudreau(deleted)
|
Re: RE: select() on UDP sockets
|
Sean Boudreau(deleted)
08/14/2009 12:17 PM
post36031
|
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
|
|
|
Oleh Derevenko(deleted)
|
Re: RE: select() on UDP sockets
|
Oleh Derevenko(deleted)
08/15/2009 7:11 AM
post36059
|
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.
|
|
|