Skip to content

Commit

Permalink
fixup! KTOR-4766 - Add basic support to use UnixSockets with CIO
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Nov 14, 2023
1 parent e68f40b commit 55130c1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
10 changes: 9 additions & 1 deletion ktor-client/ktor-client-cio/api/ktor-client-cio.api
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public final class io/ktor/client/engine/cio/CIOEngine : io/ktor/client/engine/H
public synthetic fun getConfig ()Lio/ktor/client/engine/HttpClientEngineConfig;
public fun getConfig ()Lio/ktor/client/engine/cio/CIOEngineConfig;
public fun getCoroutineContext ()Lkotlin/coroutines/CoroutineContext;
public fun getDispatcher ()Lkotlinx/coroutines/CoroutineDispatcher;
public fun getSupportedCapabilities ()Ljava/util/Set;
}

Expand All @@ -37,6 +36,15 @@ public final class io/ktor/client/engine/cio/CIOEngineContainer : io/ktor/client
public fun toString ()Ljava/lang/String;
}

public abstract interface class io/ktor/client/engine/cio/CIOHttpClientEngine : io/ktor/client/engine/HttpClientEngine {
public abstract fun createAddress (Ljava/lang/String;I)Lio/ktor/network/sockets/SocketAddress;
}

public final class io/ktor/client/engine/cio/CIOHttpClientEngine$DefaultImpls {
public static fun getSupportedCapabilities (Lio/ktor/client/engine/cio/CIOHttpClientEngine;)Ljava/util/Set;
public static fun install (Lio/ktor/client/engine/cio/CIOHttpClientEngine;Lio/ktor/client/HttpClient;)V
}

public final class io/ktor/client/engine/cio/EndpointConfig {
public fun <init> ()V
public final fun getAllowHalfClose ()Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.ktor.client.engine.cio

import io.ktor.client.engine.*
import io.ktor.utils.io.*

/**
* An asynchronous coroutine-based engine that can be used on JVM, Android, and Kotlin/Native.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ package io.ktor.server.cio

import io.ktor.events.*
import io.ktor.http.*
import io.ktor.http.cio.*
import io.ktor.server.application.*
import io.ktor.server.cio.backend.*
import io.ktor.server.cio.internal.*
import io.ktor.server.engine.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.util.*
import io.ktor.util.pipeline.*
import io.ktor.utils.io.*
import kotlinx.atomicfu.*
Expand Down Expand Up @@ -170,7 +170,7 @@ public class CIOApplicationEngine(
return transferEncoding != null || (contentLength != null && contentLength > 0)
}

private suspend fun ServerRequestScope.handleRequest(request: io.ktor.http.cio.Request) {
private suspend fun ServerRequestScope.handleRequest(request: Request) {
withContext(userDispatcher) {
val call = CIOApplicationCall(
application,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ internal class CIOApplicationRequest(
call: PipelineCall,
remoteAddress: NetworkAddress?,
localAddress: NetworkAddress?,
private val input: ByteReadChannel,
private val request: io.ktor.http.cio.Request
input: ByteReadChannel,
private val request: Request
) : BaseApplicationRequest(call) {
override val cookies: RequestCookies by lazy { RequestCookies(this) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public fun CoroutineScope.httpServer(
aSocket(selector).tcp().bind(
hostname = settings.host,
port = settings.port
)
) {
reuseAddress = settings.reuseAddress
}
},
serverJobName = CoroutineName("server-root-${settings.port}"),
acceptJobName = CoroutineName("accept-${settings.port}"),
Expand Down Expand Up @@ -68,9 +70,7 @@ public fun CoroutineScope.httpServer(
)

val acceptJob = launch(serverJob + acceptJobName) {
createServer() {
reuseAddress = settings.reuseAddress
}.use { server ->
createServer().use { server ->
socket.complete(server)

val exceptionHandler = coroutineContext[CoroutineExceptionHandler]
Expand Down

0 comments on commit 55130c1

Please sign in to comment.