For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2004 > UDP sockets and select()









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author UDP sockets and select()
Just Another Victim of the Ambient Morality

2004-09-15, 8:59 am

I wrote a program that created a UDP socket (SOCKET_DGRAM) with the
expectation of reading UDP datagrams from it but select() claims that the
socket was never ready for reading. Now, I _know_ there was data to be read
because replacing the select() call with a synchronous recvfrom() call
returns data!

So, what's up? Why doesn't select() work connectionless sockets? Is
this the same on all UNIX systems? I'm trying this on Linux 2.4.21.
Thanks...



Måns Rullgård

2004-09-15, 8:59 am

"Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> writes:

> I wrote a program that created a UDP socket (SOCKET_DGRAM) with the
> expectation of reading UDP datagrams from it but select() claims that the
> socket was never ready for reading. Now, I _know_ there was data to be read
> because replacing the select() call with a synchronous recvfrom() call
> returns data!
>
> So, what's up? Why doesn't select() work connectionless sockets? Is
> this the same on all UNIX systems? I'm trying this on Linux 2.4.21.


It has always worked for me on all Unixes I've tried. Post some code
demonstrating the problem.

--
Måns Rullgård
mru@mru.ath.cx
Dirty Vicar

2004-09-16, 8:39 pm

"Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote in message news:<zKS1d.257$RTE1.109@news01.bloor.is.net.cable.rogers.com>...
> I wrote a program that created a UDP socket (SOCKET_DGRAM) with the
> expectation of reading UDP datagrams from it but select() claims that the
> socket was never ready for reading. Now, I _know_ there was data to be read
> because replacing the select() call with a synchronous recvfrom() call
> returns data!
>
> So, what's up? Why doesn't select() work connectionless sockets? Is
> this the same on all UNIX systems? I'm trying this on Linux 2.4.21.
> Thanks...


The select() system call works just fine with UDP on linux. Trust me,
its not the kernel. Its your code.

The number one select() mistake that everyone makes at one time or
another is incorrectly setting the first agument - the maximum fd
*plus one*. Check that first.

dv
tikviva

2004-09-19, 3:58 pm

dv is right.

I've also posted a message to talk about this, and I realized that in
my implementation, I did put *1* in the first arguement on the
select(). If you can take a look at the man page, you will figure out
more. =)

- tikviva

dirtyvicar@hotmail.com (Dirty Vicar) wrote in message news:<b90dfd06.0409160810.4f56546e@posting.google.com>...
> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote in message news:<zKS1d.257$RTE1.109@news01.bloor.is.net.cable.rogers.com>...
>
> The select() system call works just fine with UDP on linux. Trust me,
> its not the kernel. Its your code.
>
> The number one select() mistake that everyone makes at one time or
> another is incorrectly setting the first agument - the maximum fd
> *plus one*. Check that first.
>
> dv

Just Another Victim of the Ambient Morality

2004-09-21, 4:00 am


"Dirty Vicar" <dirtyvicar@hotmail.com> wrote in message
news:b90dfd06.0409160810.4f56546e@posting.google.com...
> "Just Another Victim of the Ambient Morality" <ihatespam@rogers.com> wrote

in message news:<zKS1d.257$RTE1.109@news01.bloor.is.net.cable.rogers.com>...
the[color=darkred]
read[color=darkred]
Is[color=darkred]
>
> The select() system call works just fine with UDP on linux. Trust me,
> its not the kernel. Its your code.
>
> The number one select() mistake that everyone makes at one time or
> another is incorrectly setting the first agument - the maximum fd
> *plus one*. Check that first.


Ah, it turns out that that was, indeed, my problem. Thanks for the
help!

I've got another question but I'll ask that in its own thread...


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com