days
0
-24
-4
hours
-2
-1
minutes
-2
-2
seconds
-5
-3
search
It's a JEP!

JEP 380: Unix-domain socket channels

Chris Stewart
jep

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, java.nio.channels.UnixDomainSocketAddress
  • UNIX constant value in the existing java.net.StandardProtocolFamily enum
  • Static open factory methods which take a ProtocolFamily in the SocketChannel and ServerSocketChannel classes, which are useful beyond Unix-domain socket channels
  • New normative text in the SocketChannel and ServerSocketChannel classes that will distinguish Unix-domain socket channels from the existing TCP/IP types

SEE ALSO: JEP 378 – Text blocks leave preview in JDK 15

Will these changes have an effect on existing code? McMahon writes, “Existing code that uses the SocketChannel and 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.

For more information, take a look at JEP 380 over at the OpenJDK website, or see if it’s been targeted to JDK 15 by reading our Java 15 news updates.

Author
Chris Stewart
Chris Stewart is an Online Editor for JAXenter.com. He studied French at Somerville College, Oxford before moving to Germany in 2011. He speaks too many languages, writes a blog, and dabbles in card tricks.

Leave a Reply

avatar
400