All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.ch.softappeal.yass2.transport.ktor.SocketSession.kt Maven / Gradle / Ivy

There is a newer version: 5.0.0
Show newest version
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