cast: ControlSocket.send returns null when the TV hung up first
- Commit
d2e283db202b320e65576f326c769496f1590b5d- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 06:14 UTC (29 days ago)
- Parents
bb15522
A write into a socket the peer has closed answers with a broken-pipe IOException rather than the clean null the method's contract promises, which escaped into MirrorClient's configure paths and killed the negotiating coroutine silently (session stuck at Negotiating). Catch it like receive() already does. Found by MirrorClientExtraTest: pair with a TV, have it hang up, then configure a stream - the send threw instead of reporting StreamRefused. (cherry picked from commit 1c61a18a1af4d9159e021426e568077c00e687fe)
Diff
cast/src/main/java/com/vayunmathur/cast/network/ControlSocket.kt
diff --git a/cast/src/main/java/com/vayunmathur/cast/network/ControlSocket.kt b/cast/src/main/java/com/vayunmathur/cast/network/ControlSocket.ktindex 6d5522303c..271d6b74b5 100644--- a/cast/src/main/java/com/vayunmathur/cast/network/ControlSocket.kt+++ b/cast/src/main/java/com/vayunmathur/cast/network/ControlSocket.kt@@ -89,9 +89,20 @@ class ControlSocket(private val host: String, private val port: Int) { fun send(message: ControlMessage): ByteArray? { val stream = output ?: return null val body = codec.encode(message)- stream.write(ControlFraming.encode(body))- stream.flush()- return body+ return try {+ stream.write(ControlFraming.encode(body))+ stream.flush()+ body+ } catch (e: IOException) {+ // The peer hung up first: a write into that socket answers with a+ // broken pipe rather than a clean refusal, which is the same+ // "not connected" answer the null above gives - see the KDoc.+ Log.status(TAG, "the TV closed the control channel before a send", e)+ null+ } catch (e: IllegalArgumentException) {+ Log.status(TAG, "could not frame a control message", e)+ null+ } } /**