work in porgress: fixing close connection
This commit is contained in:
1 parent
c0ca802a30
commit
93dc66acc5
13 files changed
+146
-39
No files matched your search
@@ -6,15 +6,16 @@ import io.ktor.server.websocket.*
|
||||
import io.ktor.websocket.*
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.channels.ClosedReceiveChannelException
|
||||
import kotlinx.coroutines.channels.ClosedSendChannelException
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.launch
|
||||
import net.sergeych.crypto2.SigningKey
|
||||
import net.sergeych.crypto2.toDump
|
||||
import net.sergeych.kiloparsec.KiloInterface
|
||||
import net.sergeych.kiloparsec.KiloServerConnection
|
||||
import net.sergeych.mp_logger.LogTag
|
||||
import net.sergeych.mp_logger.debug
|
||||
import net.sergeych.mp_logger.warning
|
||||
import net.sergeych.kiloparsec.RemoteInterface
|
||||
import net.sergeych.mp_logger.*
|
||||
import net.sergeych.tools.AtomicCounter
|
||||
import java.time.Duration
|
||||
|
||||
@@ -49,23 +50,36 @@ fun <S> Application.setupWebsocketServer(
|
||||
}
|
||||
val server = KiloServerConnection(
|
||||
localInterface,
|
||||
ProxyDevice(input, output) { input.close() },
|
||||
ProxyDevice(input, output),
|
||||
createSession(),
|
||||
serverKey
|
||||
)
|
||||
launch { server.run() }
|
||||
log.debug { "KSC started, looking for incoming frames" }
|
||||
for( f in incoming) {
|
||||
for (f in incoming) {
|
||||
log.debug { "incoming frame: ${f.frameType}" }
|
||||
if (f is Frame.Binary)
|
||||
input.send(f.readBytes().toUByteArray().also {
|
||||
log.debug { "in frame\n${it.toDump()}" }
|
||||
})
|
||||
try {
|
||||
input.send(f.readBytes().toUByteArray().also {
|
||||
log.debug { "in frame\n${it.toDump()}" }
|
||||
})
|
||||
} catch (_: RemoteInterface.ClosedException) {
|
||||
log.info { "caught local closed exception, closing" }
|
||||
break
|
||||
} catch (_: ClosedReceiveChannelException) {
|
||||
log.info { "receive channel is closed, closing connection" }
|
||||
break
|
||||
} catch (t: Throwable) {
|
||||
log.exception { "unexpected exception, server connection will close" to t }
|
||||
break
|
||||
}
|
||||
else
|
||||
log.warning { "unknown frame type ${f.frameType}, ignoring" }
|
||||
}
|
||||
log.debug { "closing the server" }
|
||||
println("****************prec")
|
||||
cancel()
|
||||
println("****************postc")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user