Skip to content

Commit 5ca0d12

Browse files
author
Sergey Mashkov
committed
IO: fix ByteWritePacket.writePacket size update
1 parent 8b23c56 commit 5ca0d12

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

core/kotlinx-coroutines-io/src/main/kotlin/kotlinx/coroutines/experimental/io/packet/ByteWritePacketImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ internal class ByteWritePacketImpl(private val pool: ObjectPool<ByteBuffer>) : B
8888
is ByteReadPacketEmpty -> {}
8989
is ByteReadPacketSingle -> {
9090
if (p.remaining > 0) {
91+
size += p.remaining
9192
last(p.steal().also { it.compact() })
9293
}
9394
}
9495
is ByteReadPacketImpl -> {
96+
size += p.remaining
9597
while (p.remaining > 0) {
9698
last(p.steal().also { it.compact() })
9799
}

core/kotlinx-coroutines-io/src/test/kotlin/kotlinx/coroutines/experimental/io/BytePacketReaderWriterTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ class BytePacketReaderWriterTest {
314314

315315
val outer = buildPacket {
316316
append("123")
317+
assertEquals(3, size)
317318
writePacket(inner)
319+
assertEquals(6, size)
318320
append(".")
319321
}
320322

@@ -330,7 +332,9 @@ class BytePacketReaderWriterTest {
330332

331333
val outer = buildPacket {
332334
append("123")
335+
assertEquals(3, size)
333336
writePacket(inner)
337+
assertEquals(100003, size)
334338
append(".")
335339
}
336340

@@ -346,7 +350,9 @@ class BytePacketReaderWriterTest {
346350

347351
val outer = buildPacket {
348352
append("123")
353+
assertEquals(3, size)
349354
writePacketUnconsumed(inner)
355+
assertEquals(6, size)
350356
append(".")
351357
}
352358

@@ -362,7 +368,9 @@ class BytePacketReaderWriterTest {
362368

363369
val outer = buildPacket {
364370
append("123")
371+
assertEquals(3, size)
365372
writePacketUnconsumed(inner)
373+
assertEquals(100003, size)
366374
append(".")
367375
}
368376

0 commit comments

Comments
 (0)