Skip to content

Commit fd69095

Browse files
committed
Revert "KTOR-8411 CountedByteWriteChannel: fix autoFlush not working (#4800)"
This reverts commit 8ba46b9.
1 parent 8bc5a2c commit fd69095

File tree

7 files changed

+3
-50
lines changed

7 files changed

+3
-50
lines changed

ktor-io/api/ktor-io.api

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ public abstract interface class io/ktor/utils/io/BufferedByteWriteChannel : io/k
33
public abstract fun flushWriteBuffer ()V
44
}
55

6-
public final class io/ktor/utils/io/BufferedByteWriteChannel$DefaultImpls {
7-
public static fun getAutoFlush (Lio/ktor/utils/io/BufferedByteWriteChannel;)Z
8-
}
9-
106
public final class io/ktor/utils/io/ByteChannel : io/ktor/utils/io/BufferedByteWriteChannel, io/ktor/utils/io/ByteReadChannel {
117
public fun <init> ()V
128
public fun <init> (Z)V
@@ -17,7 +13,7 @@ public final class io/ktor/utils/io/ByteChannel : io/ktor/utils/io/BufferedByteW
1713
public fun flush (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1814
public fun flushAndClose (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1915
public fun flushWriteBuffer ()V
20-
public fun getAutoFlush ()Z
16+
public final fun getAutoFlush ()Z
2117
public fun getClosedCause ()Ljava/lang/Throwable;
2218
public fun getReadBuffer ()Lkotlinx/io/Source;
2319
public fun getWriteBuffer ()Lkotlinx/io/Sink;
@@ -129,16 +125,11 @@ public abstract interface class io/ktor/utils/io/ByteWriteChannel {
129125
public abstract fun cancel (Ljava/lang/Throwable;)V
130126
public abstract fun flush (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
131127
public abstract fun flushAndClose (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
132-
public abstract fun getAutoFlush ()Z
133128
public abstract fun getClosedCause ()Ljava/lang/Throwable;
134129
public abstract fun getWriteBuffer ()Lkotlinx/io/Sink;
135130
public abstract fun isClosedForWrite ()Z
136131
}
137132

138-
public final class io/ktor/utils/io/ByteWriteChannel$DefaultImpls {
139-
public static fun getAutoFlush (Lio/ktor/utils/io/ByteWriteChannel;)Z
140-
}
141-
142133
public final class io/ktor/utils/io/ByteWriteChannelKt {
143134
public static final fun cancel (Lio/ktor/utils/io/ByteChannel;)V
144135
public static final fun cancel (Lio/ktor/utils/io/ByteWriteChannel;)V
@@ -245,7 +236,6 @@ public final class io/ktor/utils/io/CountedByteWriteChannel : io/ktor/utils/io/B
245236
public fun cancel (Ljava/lang/Throwable;)V
246237
public fun flush (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
247238
public fun flushAndClose (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
248-
public fun getAutoFlush ()Z
249239
public fun getClosedCause ()Ljava/lang/Throwable;
250240
public final fun getTotalBytesWritten ()J
251241
public fun getWriteBuffer ()Lkotlinx/io/Sink;

ktor-io/api/ktor-io.klib.api

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ abstract interface io.ktor.utils.io/ByteWriteChannel { // io.ktor.utils.io/ByteW
9191
abstract fun <get-isClosedForWrite>(): kotlin/Boolean // io.ktor.utils.io/ByteWriteChannel.isClosedForWrite.<get-isClosedForWrite>|<get-isClosedForWrite>(){}[0]
9292
abstract val writeBuffer // io.ktor.utils.io/ByteWriteChannel.writeBuffer|{}writeBuffer[0]
9393
abstract fun <get-writeBuffer>(): kotlinx.io/Sink // io.ktor.utils.io/ByteWriteChannel.writeBuffer.<get-writeBuffer>|<get-writeBuffer>(){}[0]
94-
open val autoFlush // io.ktor.utils.io/ByteWriteChannel.autoFlush|{}autoFlush[0]
95-
open fun <get-autoFlush>(): kotlin/Boolean // io.ktor.utils.io/ByteWriteChannel.autoFlush.<get-autoFlush>|<get-autoFlush>(){}[0]
9694

9795
abstract fun cancel(kotlin/Throwable?) // io.ktor.utils.io/ByteWriteChannel.cancel|cancel(kotlin.Throwable?){}[0]
9896
abstract suspend fun flush() // io.ktor.utils.io/ByteWriteChannel.flush|flush(){}[0]
@@ -253,8 +251,6 @@ final class io.ktor.utils.io/CountedByteReadChannel : io.ktor.utils.io/ByteReadC
253251
final class io.ktor.utils.io/CountedByteWriteChannel : io.ktor.utils.io/ByteWriteChannel { // io.ktor.utils.io/CountedByteWriteChannel|null[0]
254252
constructor <init>(io.ktor.utils.io/ByteWriteChannel) // io.ktor.utils.io/CountedByteWriteChannel.<init>|<init>(io.ktor.utils.io.ByteWriteChannel){}[0]
255253

256-
final val autoFlush // io.ktor.utils.io/CountedByteWriteChannel.autoFlush|{}autoFlush[0]
257-
final fun <get-autoFlush>(): kotlin/Boolean // io.ktor.utils.io/CountedByteWriteChannel.autoFlush.<get-autoFlush>|<get-autoFlush>(){}[0]
258254
final val closedCause // io.ktor.utils.io/CountedByteWriteChannel.closedCause|{}closedCause[0]
259255
final fun <get-closedCause>(): kotlin/Throwable? // io.ktor.utils.io/CountedByteWriteChannel.closedCause.<get-closedCause>|<get-closedCause>(){}[0]
260256
final val isClosedForWrite // io.ktor.utils.io/CountedByteWriteChannel.isClosedForWrite|{}isClosedForWrite[0]

ktor-io/common/src/io/ktor/utils/io/ByteChannel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal const val CHANNEL_MAX_SIZE: Int = 1024 * 1024
2323
*
2424
* [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.utils.io.ByteChannel)
2525
*/
26-
public class ByteChannel(public override val autoFlush: Boolean = false) : ByteReadChannel, BufferedByteWriteChannel {
26+
public class ByteChannel(public val autoFlush: Boolean = false) : ByteReadChannel, BufferedByteWriteChannel {
2727
private val flushBuffer: Buffer = Buffer()
2828

2929
@Volatile

ktor-io/common/src/io/ktor/utils/io/ByteWriteChannel.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import kotlinx.io.*
1818
*/
1919
public interface ByteWriteChannel {
2020

21-
public val autoFlush: Boolean
22-
get() = false
23-
2421
public val isClosedForWrite: Boolean
2522

2623
public val closedCause: Throwable?
@@ -61,5 +58,5 @@ public fun ByteWriteChannel.cancel() {
6158
public suspend fun ByteWriteChannel.flushIfNeeded() {
6259
rethrowCloseCauseIfNeeded()
6360

64-
if (this.autoFlush == true || writeBuffer.size >= CHANNEL_MAX_SIZE) flush()
61+
if ((this as? ByteChannel)?.autoFlush == true || writeBuffer.size >= CHANNEL_MAX_SIZE) flush()
6562
}

ktor-io/common/src/io/ktor/utils/io/CloseHookByteWriteChannel.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ internal class CloseHookByteWriteChannel(
2020
private val delegate: ByteWriteChannel,
2121
private val onClose: suspend () -> Unit
2222
) : ByteWriteChannel by delegate {
23-
override val autoFlush: Boolean
24-
get() = delegate.autoFlush
25-
2623
override suspend fun flushAndClose() {
2724
delegate.flushAndClose()
2825
onClose()

ktor-io/common/src/io/ktor/utils/io/CountedByteWriteChannel.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ public class CountedByteWriteChannel(private val delegate: ByteWriteChannel) : B
1414
private var initial = delegate.writeBuffer.size
1515
private var flushedCount = 0
1616

17-
public override val autoFlush: Boolean
18-
get() = delegate.autoFlush
19-
2017
@OptIn(InternalAPI::class)
2118
public val totalBytesWritten: Long get() = (flushedCount + writeBuffer.size - initial).toLong()
2219

ktor-network/common/test/io/ktor/network/sockets/tests/TCPSocketTest.kt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -306,28 +306,4 @@ class TCPSocketTest {
306306
socket.awaitClosed()
307307
}
308308
}
309-
310-
@Test
311-
fun testAutoFlush() = testSockets { selector ->
312-
val tcp = aSocket(selector).tcp()
313-
val server: ServerSocket = tcp.bind("127.0.0.1", port = 0)
314-
315-
val serverConnectionPromise = async {
316-
server.accept()
317-
}
318-
319-
val clientConnection = tcp.connect("127.0.0.1", port = server.port)
320-
val serverConnection = serverConnectionPromise.await()
321-
val serverInput = serverConnection.openReadChannel()
322-
323-
val writeChannel = clientConnection.openWriteChannel(autoFlush = true)
324-
writeChannel.writeStringUtf8("Hello, world\n")
325-
val message = serverInput.readUTF8Line()
326-
assertEquals("Hello, world", message)
327-
328-
val countedWriteChannel = CountedByteWriteChannel(writeChannel)
329-
countedWriteChannel.writeStringUtf8("Hello again\n")
330-
val message2 = serverInput.readUTF8Line()
331-
assertEquals("Hello again", message2)
332-
}
333309
}

0 commit comments

Comments
 (0)