From f4d1f7386dd13fafefba64005f015e2e91140411 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Tue, 2 Apr 2019 22:25:35 +0200 Subject: Style fixes and style warnings suppress. --- .../pl/treksoft/kvision/remote/KVRemoteAgent.kt | 3 ++ .../kotlin/pl/treksoft/kvision/remote/Socket.kt | 32 ++++++++++++++++------ 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'kvision-modules/kvision-remote') diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt index 3e538bd1..9c6f8274 100644 --- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt +++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVRemoteAgent.kt @@ -377,6 +377,7 @@ open class KVRemoteAgent(val serviceManager: KVServiceManager) : Rem /** * Executes defined web socket connection */ + @Suppress("ComplexMethod", "TooGenericExceptionCaught") suspend inline fun webSocket( noinline function: suspend T.(ReceiveChannel, SendChannel) -> Unit, noinline handler: suspend (SendChannel, ReceiveChannel) -> Unit @@ -446,6 +447,7 @@ open class KVRemoteAgent(val serviceManager: KVServiceManager) : Rem /** * Executes defined web socket connection returning list objects */ + @Suppress("ComplexMethod", "TooGenericExceptionCaught") suspend inline fun webSocket( noinline function: suspend T.(ReceiveChannel, SendChannel>) -> Unit, noinline handler: suspend (SendChannel, ReceiveChannel>) -> Unit @@ -539,6 +541,7 @@ open class KVRemoteAgent(val serviceManager: KVServiceManager) : Rem /** * @suppress internal function */ + @Suppress("TooGenericExceptionCaught") suspend fun exceptionHelper(block: suspend () -> Unit) { try { block() diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/Socket.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/Socket.kt index c547ce9b..74edaba0 100644 --- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/Socket.kt +++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/Socket.kt @@ -90,6 +90,7 @@ class Socket { /** * Receive a string from a websocket. */ + @Suppress("ThrowsCount", "MagicNumber") suspend fun receive(): String { val event = eventQueue.receive() return when (event) { @@ -117,6 +118,7 @@ class Socket { /** * Send string to a websocket. */ + @Suppress("MagicNumber") fun send(obj: String) { when { isClosed() -> { @@ -130,6 +132,7 @@ class Socket { /** * Close a websocket. */ + @Suppress("MagicNumber") fun close(code: Short = 1000) { when (state) { OPEN -> ws.close(code, getReason(1000)) @@ -148,21 +151,34 @@ class Socket { private fun logError(event: Event) = console.error("An error %o occurred when connecting to ${ws.url}", event) + @Suppress("ComplexMethod", "MagicNumber") private fun getReason(code: Short): String { return when (code.toInt()) { // See http://tools.ietf.org/html/rfc6455#section-7.4.1 1000 -> "Normal closure" - 1001 -> "An endpoint is \"going away\", such as a server going down or a browser having navigated away from a page." + 1001 -> "An endpoint is \"going away\", such as a server going down or " + + "a browser having navigated away from a page." 1002 -> "An endpoint is terminating the connection due to a protocol error" - 1003 -> "An endpoint is terminating the connection because it has received a type of data it cannot accept (e.g., an endpoint that understands only text data MAY send this if it receives a binary message)." + 1003 -> "An endpoint is terminating the connection because it has received a type of data it cannot " + + "accept (e.g., an endpoint that understands only text data MAY send this if it receives a " + + "binary message)." 1004 -> "Reserved. The specific meaning might be defined in the future." 1005 -> "No status code was actually present." 1006 -> "The connection was closed abnormally, e.g., without sending or receiving a Close control frame" - 1007 -> "An endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 [http://tools.ietf.org/html/rfc3629] data within a text message)." - 1008 -> "An endpoint is terminating the connection because it has received a message that \"violates its policy\". This reason is given either if there is no other sutible reason, or if there is a need to hide specific details about the policy." - 1009 -> "An endpoint is terminating the connection because it has received a message that is too big for it to process." - 1010 -> "An endpoint (client ) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake.
Specifically, the extensions that are needed are: " - 1011 -> "A server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request." - 1015 -> "The connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified)." + 1007 -> "An endpoint is terminating the connection because it has received data within a message that " + + "was not consistent with the type of the message (e.g., non-UTF-8 " + + "[http://tools.ietf.org/html/rfc3629] data within a text message)." + 1008 -> "An endpoint is terminating the connection because it has received a message that " + + "\"violates its policy\". This reason is given either if there is no other sutible reason, or " + + "if there is a need to hide specific details about the policy." + 1009 -> "An endpoint is terminating the connection because it has received a message that is too big " + + "for it to process." + 1010 -> "An endpoint (client ) is terminating the connection because it has expected the server to " + + "negotiate one or more extension, but the server didn't return them in the response message of " + + "the WebSocket handshake.
Specifically, the extensions that are needed are: " + 1011 -> "A server is terminating the connection because it encountered an unexpected condition that " + + "prevented it from fulfilling the request." + 1015 -> "The connection was closed due to a failure to perform a TLS handshake (e.g., the server " + + "certificate can't be verified)." 4001 -> "Unexpected event" 4002 -> "You are trying to use closed socket" else -> "Unknown reason" -- cgit