-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! KTOR-6734 Fixes for Jetty 12 upgrade
- Loading branch information
Showing
24 changed files
with
489 additions
and
258 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...er/ktor-server-jetty-jakarta/jvm/src/io/ktor/server/jetty/jakarta/ContinuationCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.server.jetty.jakarta | ||
|
||
import kotlinx.io.IOException | ||
import org.eclipse.jetty.util.Callback | ||
import kotlin.coroutines.Continuation | ||
import kotlin.coroutines.resume | ||
import kotlin.coroutines.resumeWithException | ||
|
||
/** | ||
* Jetty works with a `Callback` type which succeeds or fails similar to a coroutine continuation. | ||
*/ | ||
internal fun Continuation<Unit>.asCallback(): Callback = object : Callback { | ||
override fun failed(x: Throwable?) { | ||
resumeWithException(x ?: IOException("Failed with no exception")) | ||
} | ||
override fun succeeded() { | ||
resume(Unit) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...r/ktor-server-jetty-jakarta/jvm/src/io/ktor/server/jetty/jakarta/JettyEndpointChannels.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.server.jetty.jakarta | ||
|
||
import io.ktor.utils.io.* | ||
import io.ktor.utils.io.pool.* | ||
import kotlinx.coroutines.CoroutineName | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.suspendCancellableCoroutine | ||
import org.eclipse.jetty.io.EndPoint | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
public fun CoroutineScope.connect( | ||
endpoint: EndPoint, | ||
coroutineNamePrefix: String, | ||
bufferPool: ByteBufferPool, | ||
coroutineContext: CoroutineContext | ||
): Pair<WriterJob, ReaderJob> { | ||
val inputJob: WriterJob = | ||
writer(Dispatchers.IO + coroutineContext + CoroutineName("$coroutineNamePrefix-input")) { | ||
val buffer = bufferPool.borrow() | ||
try { | ||
while (true) { | ||
suspendCancellableCoroutine { continuation -> | ||
endpoint.tryFillInterested(continuation.asCallback()) | ||
} | ||
when (endpoint.fill(buffer)) { | ||
-1 -> break | ||
0 -> continue | ||
else -> {} | ||
} | ||
channel.writeFully(buffer.flip()) | ||
buffer.compact() | ||
} | ||
} finally { | ||
bufferPool.recycle(buffer) | ||
} | ||
} | ||
|
||
val outputJob: ReaderJob = | ||
reader(Dispatchers.IO + coroutineContext + CoroutineName("$coroutineNamePrefix-output")) { | ||
val buffer = bufferPool.borrow() | ||
try { | ||
while (true) { | ||
when (channel.readAvailable(buffer)) { | ||
-1 -> break | ||
0 -> continue | ||
else -> {} | ||
} | ||
suspendCancellableCoroutine<Unit> { continuation -> | ||
endpoint.write(continuation.asCallback(), buffer.flip()) | ||
} | ||
buffer.compact() | ||
} | ||
} finally { | ||
bufferPool.recycle(buffer) | ||
} | ||
} | ||
|
||
return inputJob to outputJob | ||
} |
Oops, something went wrong.