JEP 380: Unix-domain socket channels
Another day, another JEP. The goal of JEP 380 is to introduce support for Unix-domain socket features that are common to the major Unix platforms and Windows. This will be achieved by adding a handful of API elements. Let’s take a closer look.
A new JDK Enhancement Proposal (JEP) has been put forward by Michael McMahon to add Unix-domain socket support to two APIs in the java.nio.channels package; the socket channel and server-socket channel. JEP 380 also aims to extend the inherited channel mechanism to support Unix-domain socket channels and server socket channels.
JEP 380: Unix-Domain Socket Channels
McMahon writes, “For local, inter-process communication, Unix-domain sockets are both more secure and more efficient than TCP/IP loopback connections.” This is why he proposes to add support for Unix-domain socket channels, especially now they are supported in Windows 10 and Windows Server 2019.
The intention is that Unix-domain socket channels behave much the same way as TCP/IP channels, and the features that will be supported are those that are common across the major Unix platforms as well as Windows.
SEE ALSO: Java 15 update news
So how will Unix-domain socket channels be supported in the JDK? By adding these API elements:
- A new socket address type,
UNIXconstant value in the existing
openfactory methods which take a
ServerSocketChannelclasses, which are useful beyond Unix-domain socket channels
- New normative text in the
ServerSocketChannelclasses that will distinguish Unix-domain socket channels from the existing TCP/IP types
Will these changes have an effect on existing code? McMahon writes, “Existing code that uses the
ServerSocketChannel classes often assumes that instances of
SocketAddress returned by those APIs can be blindly cast to
InetSocketAddress. This cast will fail with Unix-domain socket channels.”
Additionally, the JEP states that it is not the aim to support features that are not common across the major Unix and Windows platforms. However, McMahon notes that the topic (and unsupported features) can be revisited again later if the need arises.