From 3abb34a08e2446b8a07a0d9701783defc5d856fb Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Fri, 25 Jul 2025 16:57:43 +0200 Subject: add waitForTag and readError --- src/main/kotlin/NinePConnection.kt | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src') diff --git a/src/main/kotlin/NinePConnection.kt b/src/main/kotlin/NinePConnection.kt index 392aa8e..c5d330e 100644 --- a/src/main/kotlin/NinePConnection.kt +++ b/src/main/kotlin/NinePConnection.kt @@ -78,4 +78,40 @@ class NinePConnection(netPackTrans: NetworkPacketTransporter) : NinePTranslator } // TODO: implement methods from NinePTranslator + /** + * Wait for a 9P message with the same tag from the server. + * + * All messages prior to the returned one are discarded. + * + * @param tag The tag to wait for. + * @return A pair of (1) the size and (2) the type of the message that matches the given tag. + */ + private fun waitForTag(tag: UInt): Pair { + var s = 0u + var ty: NinePMessageType? = null + var ta = 0u + var found = false + while (!found) { + val stt = readSizeTypeTag() + s = stt.first + ty = stt.second + ta = stt.third + + if (ta == tag) { + found = true + } + } + return Pair(s, ty ?: NinePMessageType.RERROR) + } + + /** + * Read a 9P message of type Rerror, after the message size and type have already been read. + * + * @return A pair of: (1) the message tag and (2) the error message + */ + private fun readError(): Pair { + val tag = readInteger(2) + val error = readString() + return Pair(SizedMessageField(2, tag), error) + } } \ No newline at end of file -- cgit v1.2.3