File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
core/kotlinx-coroutines-io/src/main/kotlin/kotlinx/coroutines/experimental/io Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,14 @@ internal class ByteBufferChannel(
57
57
override val isClosedForWrite: Boolean
58
58
get() = closed != null
59
59
60
+ @Volatile
61
+ override var totalBytesRead: Long = 0L
62
+ private set
63
+
64
+ @Volatile
65
+ override var totalBytesWritten: Long = 0L
66
+ private set
67
+
60
68
override fun close (cause : Throwable ? ): Boolean {
61
69
if (closed != null ) return false
62
70
val newClosed = if (cause == null ) ClosedElement .EmptyCause else ClosedElement (cause)
@@ -563,13 +571,15 @@ internal class ByteBufferChannel(
563
571
564
572
writePosition = carryIndex(writePosition + n)
565
573
c.completeWrite(n)
574
+ totalBytesWritten + = n
566
575
}
567
576
568
577
private fun ByteBuffer.bytesRead (c : RingBufferCapacity , n : Int ) {
569
578
require(n >= 0 )
570
579
571
580
readPosition = carryIndex(readPosition + n)
572
581
c.completeRead(n)
582
+ totalBytesRead + = n
573
583
resumeWriteOp()
574
584
}
575
585
Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ public interface ByteReadChannel {
30
30
*/
31
31
public var readByteOrder: ByteOrder
32
32
33
+ /* *
34
+ * Number of bytes read from the channel.
35
+ * It is not guaranteed to be atomic so could be updated in the middle of long running read operation.
36
+ */
37
+ public val totalBytesRead: Long
38
+
33
39
/* *
34
40
* Reads all available bytes to [dst] buffer and returns immediately or suspends if no bytes available
35
41
* @return number of bytes were read or `-1` if the channel has been closed
Original file line number Diff line number Diff line change @@ -36,6 +36,12 @@ public interface ByteWriteChannel {
36
36
*/
37
37
public var writeByteOrder: ByteOrder
38
38
39
+ /* *
40
+ * Number of bytes written to the channel.
41
+ * It is not guaranteed to be atomic so could be updated in the middle of write operation.
42
+ */
43
+ public val totalBytesWritten: Long
44
+
39
45
/* *
40
46
* Writes as much as possible and only suspends if buffer is full
41
47
*/
You can’t perform that action at this time.
0 commit comments