From 1df2d730b31f5b59f13f132d0129192ef3d4c71a Mon Sep 17 00:00:00 2001 From: Anton Malinskiy Date: Fri, 19 Apr 2024 00:04:17 +1000 Subject: [PATCH] feat(adam): support larger payloads for protocol string --- adam/src/main/kotlin/com/malinskiy/adam/extension/Socket.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/adam/src/main/kotlin/com/malinskiy/adam/extension/Socket.kt b/adam/src/main/kotlin/com/malinskiy/adam/extension/Socket.kt index 4908f201d..770d4d026 100644 --- a/adam/src/main/kotlin/com/malinskiy/adam/extension/Socket.kt +++ b/adam/src/main/kotlin/com/malinskiy/adam/extension/Socket.kt @@ -26,6 +26,7 @@ import com.malinskiy.adam.transport.Socket import com.malinskiy.adam.transport.TransportResponse import com.malinskiy.adam.transport.use import com.malinskiy.adam.transport.withDefaultBuffer +import com.malinskiy.adam.transport.withMaxPacketBuffer import kotlinx.coroutines.yield import java.io.File import java.nio.ByteBuffer @@ -41,6 +42,7 @@ suspend fun Socket.copyTo(transformer: ResponseTransformer, buffer: ByteA limit == null || (limit - processed) > buffer.size -> { buffer.size } + else -> { (limit - processed).toInt() } @@ -54,11 +56,13 @@ suspend fun Socket.copyTo(transformer: ResponseTransformer, buffer: ByteA available < 0 -> { break@loop } + available > 0 -> { transformer.process(buffer, 0, available) processed += available yield() } + else -> { yield() continue@loop @@ -98,7 +102,7 @@ suspend fun Socket.readOptionalProtocolString(): String? { * @throws RequestRejectedException */ suspend fun Socket.readProtocolString(): String { - withDefaultBuffer { + withMaxPacketBuffer { val transformer = StringResponseTransformer() val copied = copyTo(transformer, this, limit = 4L) val length = transformer.transform()