22 lines
658 B
Kotlin
22 lines
658 B
Kotlin
package com.shr4pnel.ferretirc.net
|
|
|
|
import io.ktor.network.sockets.Socket
|
|
import io.ktor.network.sockets.openWriteChannel
|
|
import io.ktor.utils.io.ByteWriteChannel
|
|
import io.ktor.utils.io.writeFully
|
|
import kotlinx.coroutines.CoroutineScope
|
|
import kotlinx.coroutines.launch
|
|
|
|
class MessageWriter(socket: Socket, scope: CoroutineScope): MessageIO(socket, scope) {
|
|
private lateinit var send: ByteWriteChannel
|
|
|
|
override suspend fun start() {
|
|
send = socket.openWriteChannel()
|
|
scope.launch {
|
|
for (msg in outgoingMessages) {
|
|
send.writeFully(msg.toWire())
|
|
send.flush()
|
|
}
|
|
}
|
|
}
|
|
} |