Re: UDP socket close problem
From: Mark Stevens (mas78910_at_hotmail.com)
Date: 12/04/03
- Next message: Ralf Fassel: "Re: How does one use setuid?"
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Writing to i/o at a lower level"
- In reply to: Michael Kerrisk: "Re: UDP socket close problem"
- Next in thread: David Schwartz: "Re: UDP socket close problem"
- Reply: David Schwartz: "Re: UDP socket close problem"
- Reply: Barry Margolin: "Re: UDP socket close problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 4 Dec 2003 01:53:52 -0800
Michael Kerrisk <michael-dot-kerrisk-at-gmx-dot-net@NOSPAM.COM> wrote in message news:<f45psv89lfd5sj2ga5omoau1hsbjg33f50@4ax.com>...
<snip>
>
> Now, with a bit of work, I can replicate the behaviour you describe
> (though I'm not quite sure why things are done this way). But what
> you are doing doesn't seem to make sense in the light of your first
> paragraph. You say that you choose an ephemeral port by binding to
> port 0. That's fine. But in the second para you talk about another
> server binding to that same port. Why are you doing this -- why does
> it matter to this server that it binds to the same ephemeral port as
> the earlier server invocation? And why do you have clients sending
> datagrams to a port to which there is no server? (I ask this because
> it sounds like the problem may be solved by a different -- perhaps
> better -- application design.)
>
> (By the way, SO_REUSEADDR seems to have no effect on this behaviour.)
>
Thanks for looking into this - it gives me some consolation to know
that it's not just my code.
As to why it's being done this way: The real situation is more
complicated than I describe in my orignal post, but there I wanted to
convey the problem without clouding the issue with details.
I have lots of client processes which need to be able to send
datagrams to a server, starting and stopping transmission at the
request of a user. It is possible that many of these clients will be
sending data to the server at once. If these client processes all
send their data to a single port at the server then the server needs
to untangle where these datagrams come from in order for them to be
handled properly.
To avoid this difficulty I have the following scheme: a management
process finds a free port using bind(0), as described in my original
post. It notes the port number and closes the matching socket
descriptor. The management process then communicates the port number
and server name to the client that is required to start sending data,
it also communciates the port number to the server to start receiving
datagrams on. The client then starts sending data to the specified
port on the server and the server starts 'listening' to the specified
port. In this way the server knows that any data received on a
particular port came from a particular client and can thus deal with
it very easily.
This might sound overly complicated but the software project I'm
working on already has the infrastructure in place to make it the
easiest solution.
I'm certain that a lot of people will disagree with this design, but I
don't want to draw attention away from my main issue, which is the
inconsistency in behaviour between kernel-allocated and hand-allocated
ports.
Thanks,
Mark Stevens
- Next message: Ralf Fassel: "Re: How does one use setuid?"
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Writing to i/o at a lower level"
- In reply to: Michael Kerrisk: "Re: UDP socket close problem"
- Next in thread: David Schwartz: "Re: UDP socket close problem"
- Reply: David Schwartz: "Re: UDP socket close problem"
- Reply: Barry Margolin: "Re: UDP socket close problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|