https://kotlinlang.org logo
#ktor
Title
# ktor
d

Didier Villevalois

09/06/2021, 3:34 PM
[ktor-network] @e5l Hi, I am starting to think about the implementation for the support of unix domain sockets (aka ipc sockets) in ktor-network as I proposed before. After delving in the code, I already have a few questions: 1. Should I first open a ticket on YouTrack before submitting a PR? 2. It seems that I would not have a lot to do for the native part (did not look at the Jvm part yet) because the posix API is the same to use IPC sockets modulo some constants (mainly the address family,
AF_UNIX
instead of
AF_INET
). However, I think I would need to do some (problematic?) refactoring first. ◦
AConnectedSocket
and
ABoundSocket
both use
NetworkAddress
for their
remoteAddress
and
localAddress
which is problematic, because too restrictive. Presumably, I would have to introduce some super-class to
NetworkAddress
and another sibling to
NetworkAddress
(say
UnixAddress
). This refactoring could ripple a lot. ◦ Rename
TCPSocketNative
to
ByteStreamSocketNative
as its implementation would be used as is for both TCP byte-stream sockets and IPC byte-stream sockets. (Same for
TCPServerSocketNative
) ◦ Adapt the first two lines of both
connect()
and
bind()
(in
ConnectUtilsNative.kt
) to also handle the
UnixAddress
. The rest of the code would (more or less) stay as is. That's all for now. I am quite ready to jump on the wagon, as there won't be much work to do (and I desperately need this 🤪). Please guide me on how I should proceed. Thanks in advance.
e

e5l

09/06/2021, 3:35 PM
Hey @Didier Villevalois, thanks for the questions: 1. There is a ticket on YT 2. It should be OK, the only things to be careful is Public API surface. Feel free to ping me if you have any questions 🙂
d

Didier Villevalois

09/06/2021, 3:41 PM
OK, found the issue: https://youtrack.jetbrains.com/issue/KTOR-781. When you say "public API surface", you mean Ktor's own API right ? Because everything in
ktor-network
and
ktor-utils
(
NetworkAddress
is there) is internal, am I wrong?
@e5l So it seems to me that the only public use of
NetworkAddress
is in the return type of
ProxyConfig.resolveAddress()
.
ProxyConfig
is public and used as the type of the
proxy
attribute of
HttpClientEngineConfig
. Ideally, I would like to rename
NetworkAddress
as
InetSocketAddress
in order to have the hierarchy: •
SocketAddress
InetSocketAddress
UnixSocketAddress
Do you think that would be a pain point? We could have a typealias from
NetworkAddress
to
InetSocketAddress
. (Note that
NetworkAddress
on jvm is already a typealias to
SocketAddress
.)
@e5l I've got a bigger problem.
java.net.UnixDomainSocketAddress
is only from java 16. Ktor targets an older java. I don't think there is a way to tell Kotlin to ignore if the actual class does not exist. I would have to make a parallel hierarchy (without
actual typealias
) and test if the feature exist dynamically. Is that the way to go ?