RFR [11] 8200304: TwoStacksPlainDatagramSocketImpl and socket cleaner

Chris Hegarty chris.hegarty at oracle.com
Thu Mar 29 10:10:02 UTC 2018


> On 28 Mar 2018, at 20:47, Chris Hegarty <chris.hegarty at oracle.com> wrote:
> ...
> Right, unconditionally unregistering and re-registering would be easier
> to follow, and then try-finally would not be required either.  I’ll try this,
> test it, and report back.

This is much simpler.
  
      @Override
      protected synchronized void bind0(int lport, InetAddress laddr)
          throws SocketException
      {
+         // The native bind0 may close one or both of the underlying file
+         // descriptors, and even create new sockets, so the safest course of
+         // action is to unregister the socket cleaners, and register afterwards.
+         SocketCleanable.unregister(fd);
+         SocketCleanable.unregister(fd1);
+ 
          bind0(lport, laddr, exclusiveBind);
+
+         SocketCleanable.register(fd);
+         SocketCleanable.register(fd1);
      }
  
      protected synchronized void receive(DatagramPacket p)
          throws IOException {
          try {


webrev:
  http://cr.openjdk.java.net/~chegar/8200304/01/

-Chris.


More information about the net-dev mailing list