Skip to content

Commit

Permalink
Merge pull request #113 from Malinskiy/feature/support-larger-payloads
Browse files Browse the repository at this point in the history
feat(adam): support larger payloads for protocol string
  • Loading branch information
Malinskiy authored Apr 18, 2024
2 parents 0ce0720 + 1df2d73 commit d4ea7ee
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion adam/src/main/kotlin/com/malinskiy/adam/extension/Socket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +42,7 @@ suspend fun <T> Socket.copyTo(transformer: ResponseTransformer<T>, buffer: ByteA
limit == null || (limit - processed) > buffer.size -> {
buffer.size
}

else -> {
(limit - processed).toInt()
}
Expand All @@ -54,11 +56,13 @@ suspend fun <T> Socket.copyTo(transformer: ResponseTransformer<T>, buffer: ByteA
available < 0 -> {
break@loop
}

available > 0 -> {
transformer.process(buffer, 0, available)
processed += available
yield()
}

else -> {
yield()
continue@loop
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d4ea7ee

Please sign in to comment.