Unix domain sockets (UDS, AF_UNIX) in System.inheritedChannel() and elsewhere in Java
Alan Bateman
Alan.Bateman at oracle.com
Fri Jul 19 16:10:43 UTC 2019
On 19/07/2019 16:35, František Kučera wrote:
>
> 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
>
This is something that we've prototyped several times over the years but
never came to a conclusion on whether to attempt to include it or not.
No objection to exploring it again but I think it should be prototyped
as a JDK-specific API, probably jdk.net module. This is the approach we
have been discussing on nio-dev for the RDMA socket API. In terms of API
then introducing a SocketAddress sub-class for Unix domain sockets looks
right, although it should probably be created with a Path or String
rather than a byte array. For the RDMA sockets we have a factory class
to create SocketChannel or ServerSocketChannels that will probably work
here too.
Windows and pipes is something that is worth discussing too as we didn't
do anything on that in previous explorations.
-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/net-dev/attachments/20190719/1cff4735/attachment.html>
More information about the net-dev
mailing list