Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Unix Sockets on Windows #4479

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ktor-network/jvm/src/io/ktor/network/sockets/SocketImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal class SocketImpl<out S : SocketChannel>(
if (channel.finishConnect()) {
// TCP has a well known self-connect problem, which client can connect to the client itself
// without any program listen on the port.
if (selfConnect()) {
if (inetSelfConnect()) {
if (java7NetworkApisAvailable) {
channel.close()
} else {
Expand All @@ -74,7 +74,7 @@ internal class SocketImpl<out S : SocketChannel>(
interestOp(SelectInterest.CONNECT, state)
}

private fun selfConnect(): Boolean {
private fun inetSelfConnect(): Boolean {
val localAddress = if (java7NetworkApisAvailable) {
channel.localAddress
} else {
Expand All @@ -93,6 +93,10 @@ internal class SocketImpl<out S : SocketChannel>(
val localInetSocketAddress = localAddress as? java.net.InetSocketAddress
val remoteInetSocketAddress = remoteAddress as? java.net.InetSocketAddress

if (localInetSocketAddress == null && remoteInetSocketAddress == null) {
return false
}

val localHostAddress = localInetSocketAddress?.address?.hostAddress ?: ""
val remoteHostAddress = remoteInetSocketAddress?.address?.hostAddress ?: ""
val isRemoteAnyLocalAddress = remoteInetSocketAddress?.address?.isAnyLocalAddress ?: false
Expand Down