Unix domain sockets (UDS, AF_UNIX) in System.inheritedChannel() and elsewhere in Java

František Kučera franta-java at frantovo.cz
Fri Jul 19 15:35:49 UTC 2019


Hello,

I am interested in the unix domain sockets (UDS, AF_UNIX) support in Java.

Java is able to inherit a channel from the parent process and access it 
through System.inheritedChannel(). The channel is passed as an open file 
descriptor (FD) to Java form the parent process which is usually some 
superserver (like xinetd or systemd) or some other loader*. The channel 
might be both a ServerSocketChannel (accept() is called in Java) and a 
SocketChannel (accept() is called once in the parent process) or a 
DatagramChannel. And it might be TCP, UDP or UDS. But the UDS support is 
a bit incomplete.

I want to make the UDS support better so I wrote a proof-of-concept 
patch – see attached .diff and webrev: 
http://frantovo.cz/disk/openjdk-uds-08/ It still requires a lot of work 
(clean-up, refactoring, portability, security manager, documentation, 
testing…) but it seems feasible to me.

What already works in Java:

  * listening on an inherited UDS channel (ServerSocketChannel) – e.g.
    Jetty or Tomcat are able to listen and serve HTTP requests on UDS
    instead of TCP
  * receiving datagrams from UDS

What my proof-of-concept patch adds:

  * class UnixSocketAddress extends SocketAddress
  * support also for a single inherited UDS connection (SocketChannel)
  * getting correct local and remote addresses (instead of an
    InetAddress with some random IP and port)
  * creating new server and client UDS channels from Java

I am looking for a sponsor/mentor who will help me finish this task 
through wise advice and peer review.

My further plans:

  * finish the datagram part (sending responses to UDS does not work yet)
  * allow inheritance of multiple channels/sockets
  * getting client credentials (user name and group – where available)
  * maybe passing FDs through UDS (where available)
  * maybe FileChannel for accessing ordinary files inherited from the
    parent as FDs

Franta

*) might be just few lines in C e.g. https://blog.frantovo.cz/c/372/#toc_12

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/net-dev/attachments/20190719/22a20db8/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: openjdk-uds-08.diff
Type: text/x-patch
Size: 37616 bytes
Desc: not available
URL: <https://mail.openjdk.java.net/pipermail/net-dev/attachments/20190719/22a20db8/openjdk-uds-08-0001.diff>


More information about the net-dev mailing list