|
@@ -80,23 +80,23 @@ internal class KtorLineBufferedSocket(coroutineScope: CoroutineScope, private va
|
80
|
80
|
|
81
|
81
|
override val receiveChannel
|
82
|
82
|
get() = produce {
|
83
|
|
- val lineBuffer = ByteArray(4096)
|
84
|
|
- var index = 0
|
|
83
|
+ val lineBuffer = ByteArray(16384)
|
|
84
|
+ var nextByteOffset = 0
|
85
|
85
|
while (!readChannel.isClosedForRead) {
|
86
|
|
- var start = index
|
87
|
|
- val count = readChannel.readAvailable(lineBuffer, index, lineBuffer.size - index)
|
88
|
|
- for (i in index until index + count) {
|
|
86
|
+ var lineStart = 0
|
|
87
|
+ val bytesRead = readChannel.readAvailable(lineBuffer, nextByteOffset, lineBuffer.size - nextByteOffset)
|
|
88
|
+ for (i in nextByteOffset until nextByteOffset + bytesRead) {
|
89
|
89
|
if (lineBuffer[i] == CARRIAGE_RETURN || lineBuffer[i] == LINE_FEED) {
|
90
|
|
- if (start < i) {
|
91
|
|
- val line = lineBuffer.sliceArray(start until i)
|
|
90
|
+ if (lineStart < i) {
|
|
91
|
+ val line = lineBuffer.sliceArray(lineStart until i)
|
92
|
92
|
log.fine { "<<< ${String(line)}" }
|
93
|
93
|
send(line)
|
94
|
94
|
}
|
95
|
|
- start = i + 1
|
|
95
|
+ lineStart = i + 1
|
96
|
96
|
}
|
97
|
97
|
}
|
98
|
|
- lineBuffer.copyInto(lineBuffer, 0, start)
|
99
|
|
- index = count + index - start
|
|
98
|
+ lineBuffer.copyInto(lineBuffer, 0, lineStart)
|
|
99
|
+ nextByteOffset += bytesRead - lineStart
|
100
|
100
|
}
|
101
|
101
|
}
|
102
|
102
|
|