summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/NinePConnection.kt36
1 files changed, 36 insertions, 0 deletions
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<UInt, NinePMessageType> {
+ 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<SizedMessageField, String> {
+ val tag = readInteger(2)
+ val error = readString()
+ return Pair(SizedMessageField(2, tag), error)
+ }
} \ No newline at end of file