DatagramSocket vs DatagramChannel behavior in disconnect()

Florian Weimer fweimer at redhat.com
Fri Feb 28 08:19:30 PST 2014


On 02/28/2014 04:57 PM, Florian Weimer wrote:

> With an explicit bind, it looks like this:
>
> DatagramSocket open: /10.33.200.60:45307
> DatagramChannel open: /10.33.200.60:50218
> DatagramSocket connect: /10.33.200.60:45307
> DatagramChannel connect: /10.33.200.60:50218
> DatagramSocket disconnect: /10.33.200.60:45307
> DatagramChannel disconnect: /10.33.200.60:0
> DatagramSocket reconnect: /10.33.200.60:45307
> DatagramChannel reconnect: /10.33.200.60:46574
> DatagramSocket redisconnect: /10.33.200.60:45307
> DatagramChannel redisconnect: /10.33.200.60:0
>
> So the channel still does not preserve the port.

That's because I only did an explicit bind for the address part of the 
name.  If I bind the port as well, DatagramChannel will preserve it as 
well.  This corresponds 1:1 to the Linux kernel behavior, which is not 
surprising because the DatagramChannel native disconnect does not do any 
name binding after connect(AF_UNSPEC).

> With a strong end system model (do we support any of those?), preserving
> the address would result in unusable sockets, so not preserving the
> address is probably the right thing to do.

Linux follows the weak end system model (obviously).

-- 
Florian Weimer / Red Hat Product Security Team


More information about the nio-dev mailing list