Keep Vsock server running, better error responses
This commit is contained in:
parent
ea983cf990
commit
f985f31c0a
@ -27,7 +27,7 @@ class VsockServer(private val cid: Int, private val port: Int, httpBindPort: Int
|
||||
fun start() {
|
||||
server = ServerVSock()
|
||||
try {
|
||||
server?.bind(VSockAddress(cid, port)) //For any CID use VSockAddress.VMADDR_CID_ANY
|
||||
server?.bind(VSockAddress(VSockAddress.VMADDR_CID_ANY, port)) //For any CID use VSockAddress.VMADDR_CID_ANY
|
||||
logger.info { "Vsock Bound on Cid: ${server?.localCid}" }
|
||||
|
||||
server?.accept()?.use { peerVSock ->
|
||||
@ -43,7 +43,8 @@ class VsockServer(private val cid: Int, private val port: Int, httpBindPort: Int
|
||||
Json.decodeFromString<VsockApiRequest>(receivedData)
|
||||
} catch (e: Exception) {
|
||||
logger.error { "Failed to parse JSON: ${e.message}" }
|
||||
peerVSock.outputStream?.write("Invalid JSON format".toByteArray(StandardCharsets.UTF_8))
|
||||
val errorMessage = "{\"error\":\"Invalid JSON format\", \"received\":\"${receivedData}\"}"
|
||||
peerVSock.outputStream?.write(errorMessage.toByteArray(StandardCharsets.UTF_8))
|
||||
return
|
||||
}
|
||||
|
||||
@ -57,9 +58,10 @@ class VsockServer(private val cid: Int, private val port: Int, httpBindPort: Int
|
||||
}
|
||||
} catch (ex: IOException) {
|
||||
logger.error { "Error starting Vsock: ${ex.message}" }
|
||||
} finally {
|
||||
stop()
|
||||
}
|
||||
/*finally { // We have to keep the server running
|
||||
stop()
|
||||
}*/
|
||||
}
|
||||
|
||||
private suspend fun handleApiCall(request: VsockApiRequest): String {
|
||||
|
Loading…
x
Reference in New Issue
Block a user