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 15bc894
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
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
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
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
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 15bc894

Please sign in to comment.