Synchronized writes.

This commit is contained in:
Koen 2024-01-07 14:19:03 +01:00
parent 176814a715
commit 698725d611

View file

@ -90,6 +90,7 @@ class FCastCastingDevice : CastingDevice {
private var _thread: Thread? = null
private var _pingThread: Thread? = null
private var _lastPongTime = -1L
private var _outputStreamLock = Object()
constructor(name: String, addresses: Array<InetAddress>, port: Int) : super() {
this.name = name;
@ -476,6 +477,7 @@ class FCastCastingDevice : CastingDevice {
}
private fun send(opcode: Opcode, message: String? = null) {
synchronized (_outputStreamLock) {
try {
val data: ByteArray = message?.encodeToByteArray() ?: ByteArray(0)
val size = 1 + data.size
@ -506,6 +508,7 @@ class FCastCastingDevice : CastingDevice {
throw e
}
}
}
private inline fun <reified T> send(opcode: Opcode, message: T) {
try {