[F] Fix other people disconnecting causing broadcast to crash

pull/109/head
Azalea 2025-01-15 12:57:04 -05:00
parent 7363bb307d
commit 830b10878e
1 changed files with 11 additions and 3 deletions

View File

@ -27,6 +27,7 @@ data class ActiveClient(
val socket: Socket,
val reader: BufferedReader,
val writer: BufferedWriter,
val thread: Thread = Thread.currentThread(),
// <Stream ID, Destination client stub IP>
val tcpStreams: MutableMap<UInt, UInt> = mutableMapOf(),
val pendingStreams: MutableSet<UInt> = mutableSetOf(),
@ -39,9 +40,16 @@ data class ActiveClient(
fun send(msg: Msg) {
writeMutex.withLock {
writer.write(msg.toString())
writer.newLine()
writer.flush()
try {
writer.write(msg.toString())
writer.newLine()
writer.flush()
}
catch (e: Exception) {
log.error("Error sending message", e)
socket.close()
thread.interrupt()
}
}
}
}