Create MessageParser, use in Reader, add logs
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.shr4pnel.ferretirc.net
|
||||
|
||||
import com.shr4pnel.ferretirc.net.messages.MessageIO
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import io.ktor.network.sockets.Socket
|
||||
import io.ktor.network.sockets.openWriteChannel
|
||||
import io.ktor.utils.io.ByteWriteChannel
|
||||
@@ -7,16 +9,17 @@ import io.ktor.utils.io.writeFully
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class MessageWriter(socket: Socket, scope: CoroutineScope): MessageIO(socket, scope) {
|
||||
class MessageWriter(socket: Socket, scope: CoroutineScope) : MessageIO(socket, scope) {
|
||||
private lateinit var send: ByteWriteChannel
|
||||
private val logger = KotlinLogging.logger("MessageWriter")
|
||||
|
||||
override suspend fun start() {
|
||||
override fun start() = scope.launch {
|
||||
send = socket.openWriteChannel()
|
||||
scope.launch {
|
||||
for (msg in outgoingMessages) {
|
||||
send.writeFully(msg.toWire())
|
||||
send.flush()
|
||||
}
|
||||
|
||||
for (msg in outgoingMessages) {
|
||||
logger.debug { msg.toWireIntermediate() }
|
||||
send.writeFully(msg.toWire())
|
||||
send.flush()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user