On 21/07/2019 11:01, František Kučera wrote:
I would also prefer String or Path in the Java API but
sockaddr_un.sun_path is defined in the POSIX standard as a byte array
and it might be not only a file path but there are also "abstract"
paths which have no representation on the filesystem – they start with
\0 null-byte and the abstract path is the whole rest of the array. So
lossless mapping between byte arrays and strings will be difficult or
maybe impossible (the "@" character is sometimes used in the UI
instead of the \0 but "@" is also valid character on the filesystem
path, so there are ambiguities). Although Java Sting can hold the \0
bytes, depending on local encoding there might be edge cases where the
path is a valid byte array (sun_path) and is addressable from the
POSIX API but is not a valid String in given encoding. Maybe there
might be subclasses for abstract and non-abstract addresses... but in
the prototype, I looked for the simplest solution (but buggy, I know,
it e.g. includes all the \0s in the toString() representation).
The implementation of Path on Unix systems uses bytes so will preserve
the original file path, you just need to be careful to avoid Path ->
String round trips.
:
The System.inheritedChannel() is in the Java base – there might be
some indirect/optional dependency from the base to the module. Idea:
create an SPI interface with methods canCreateChannel(fd) and
createChannel(fd); the new module will implement this interface for
AF_UNIX file descriptors; and the System.inheritedChannel() will
lookup implementations of this interface and try to get the channel
from them; and if no implementation will return a channel, it will
fallback to the current implementation. Is it possible solution?
May the java.net.UnixSocketAddress and
java.net.StandardProtocolFamily.UNIX stay where they are?
For the prototype then you should be able to put UnixSocketAddress and
UnixProtocolFamily in jdk.net too. On naming, one of the discussion
points will be whether it should be LocalSocketAddress as PF_UNIX is
deprecated in favor of PF_LOCAL on some systems. A bigger discussion
point will be whether to introduce new channel types rather than trying
to have alternative implementations of
SocketChannel/ServerSocketChannel. The approach that we've been taking
with the RDMA API is to use the existing API and have the factory
methods that that create the RDMA socket channel specify the differences.
My primary goal was to fix the wrong addresses (random IP and port)
returned from System.inheritedChannel()
If fd 0 is a Unix domain socket then inheritedChannel should return
null. Are you sure you it's returning a SocketChannel to something that
is not a stream or datagram socket? If so then then this is a bug that
should be looked into.
-Alan