mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-06-24 21:25:23 +00:00
Added synchronization to sender.
This commit is contained in:
parent
48cf03f78b
commit
6f90cf7bb6
2 changed files with 31 additions and 28 deletions
|
@ -62,9 +62,11 @@ class FCastSession(outputStream: OutputStream, private val _remoteSocketAddress:
|
||||||
private var _packetLength = 0
|
private var _packetLength = 0
|
||||||
private var _state = SessionState.WaitingForLength
|
private var _state = SessionState.WaitingForLength
|
||||||
private var _outputStream: DataOutputStream? = DataOutputStream(outputStream)
|
private var _outputStream: DataOutputStream? = DataOutputStream(outputStream)
|
||||||
|
private var _outputStreamLock = Object()
|
||||||
val id = UUID.randomUUID()
|
val id = UUID.randomUUID()
|
||||||
|
|
||||||
fun send(opcode: Opcode, message: String? = null) {
|
fun send(opcode: Opcode, message: String? = null) {
|
||||||
|
synchronized(_outputStreamLock) {
|
||||||
try {
|
try {
|
||||||
val data: ByteArray = message?.encodeToByteArray() ?: ByteArray(0)
|
val data: ByteArray = message?.encodeToByteArray() ?: ByteArray(0)
|
||||||
val size = 1 + data.size
|
val size = 1 + data.size
|
||||||
|
@ -95,6 +97,7 @@ class FCastSession(outputStream: OutputStream, private val _remoteSocketAddress:
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline fun <reified T> send(opcode: Opcode, message: T) {
|
inline fun <reified T> send(opcode: Opcode, message: T) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -142,7 +142,7 @@ class NetworkService : Service() {
|
||||||
session.send(opcode, message)
|
session.send(opcode, message)
|
||||||
Log.i(TAG, "Opcode sent (opcode = $opcode) ${session.id}")
|
Log.i(TAG, "Opcode sent (opcode = $opcode) ${session.id}")
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
Log.w(TAG, "Failed to send playback error", e)
|
Log.w(TAG, "Failed to send opcode (opcode = $opcode) ${session.id}", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue