jvmMain.ch.softappeal.yass2.transport.ktor.SocketSession.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yass2-jvm Show documentation
Show all versions of yass2-jvm Show documentation
Yet Another Service Solution
package ch.softappeal.yass2.transport.ktor
import ch.softappeal.yass2.remote.session.*
import ch.softappeal.yass2.transport.*
import io.ktor.network.sockets.*
class SocketConnection internal constructor(private val config: SessionConfig, val socket: Socket) : Connection {
private val writeChannel = socket.openWriteChannel()
override suspend fun write(packet: Packet?) {
writeChannel.write(config, packet)
writeChannel.flush()
}
override fun closed() = socket.close()
}
suspend fun Socket.handleSession(config: SessionConfig) = use {
val readChannel = openReadChannel()
SocketConnection(config, this).receiveLoop(config.sessionFactory) { readChannel.read(config) as Packet? }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy