> DatagramSocket has a DatagramSocket.setDatagramSocketImplFactory method that 
> allows to globally replace the default DatagramSocket/MulticastSocket 
> implementation provided by the JDK. This was provided as a way in early JDK 
> releases to replace the system wide implementation. It has been mostly 
> obsolete since Java 1.4. A DatagramSocket can be created to use a custom 
> implementation by extending DatagramSocket and using the protected 
> constructor that takes the impl as a parameter. However, MulticastSocket 
> doesn't provide such a constructor.
> 
> Though DatagramSocket can be subclassed to provide a custom implementation, 
> MulticastSocket, if subclassed, will still create its default implementation, 
> even when all methods of MulticastSocket are overridden in order not to use 
> it. This will create a file descriptor / socket leak.
> 
> The only solution to avoid that is currently to replace the default 
> DatagramSocketImplFactory by calling the static 
> DatagramSocket.setDatagramSocketImplFactory. We need a better solution.
> 
> The solution proposed in this RFE is to allow DatagramSocket to both send and 
> receive multicast datagrams. DatagramSocket has always had the ability to 
> send multicast packets. In Java 15, DatagramSocket has been improved to 
> support getting/setting multicast options. This change proposes to move 
> `joinGroup(SocketAddress, NetworkInterface)` and `leaveGroup(SocketAddress, 
> NetworkInterface)` up from MulticastSocket into DatagramSocket.
> 
> An application that needs to completely replace the default multicast 
> implementation, and that cannot be easily updated to use DatagramChannel, can 
> do so by subclassing DatagramSocket instead.
> 
> In addition, this change improves the documentation of DatagramSocket and 
> MulticastSocket to show how convenience getters/setters map to 
> StandardSocketOptions, and adds an `@apiNote` to show how DatagramSocket can 
> be used for multicasting.
> 
> Specdiff can be seen here:
> http://cr.openjdk.java.net/~dfuchs/ds-ms-8237352-specdiff.07/overview-summary.html
> 
> CSR:
> https://bugs.openjdk.java.net/browse/JDK-8260667

Daniel Fuchs has updated the pull request with a new target base due to a merge 
or a rebase. The incremental webrev excludes the unrelated changes brought in 
by the merge/rebase. The pull request contains ten additional commits since the 
last revision:

 - Integrated review comments.
 - Merge branch 'master' into ds-ms-8237352
 - Integrated review comments.
 - Fixup @bug in the tests
 - Fixup @see for leaveGroup
 - Restore @apiNote for leaveGroup
 - Overrides in MulticastSocket don't need the @apiNote
 - 8237352: Evaluate how to write a custom DatagramSocket/MulticastSocket 
without using DatagramSocketImplFactory
 - 8237352: Evaluate how to write a custom DatagramSocket/MulticastSocket 
without using DatagramSocketImplFactory

-------------

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/2312/files
  - new: https://git.openjdk.java.net/jdk/pull/2312/files/da9a5862..83dda0b3

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=2312&range=05
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=2312&range=04-05

  Stats: 2816 lines in 110 files changed: 1459 ins; 968 del; 389 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2312.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2312/head:pull/2312

PR: https://git.openjdk.java.net/jdk/pull/2312

Reply via email to