summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/kotlin/Connection.kt106
1 files changed, 0 insertions, 106 deletions
diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt
index 7addc10..3f920e7 100644
--- a/src/main/kotlin/Connection.kt
+++ b/src/main/kotlin/Connection.kt
@@ -50,112 +50,6 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator {
this.tl.close()
}
- /**
- * Read an [len] bytes long unsigned integer number from the connection.
- *
- * In 9P, binary numbers (non-textual) are specified in little-endian order (least significant byte first).
- *
- * @param len The length of the integer number in bytes. If zero, nothing is read.
- * @return the number's value.
- * @throws java.io.IOException if the message could not be correctly received.
- */
- private fun readInteger(len: ULong): BigInteger {
- val bytes = this.tl.receive(len)
- var value = 0.toBigInteger()
- for (i in 0..<bytes.size) {
- value += bytes[i].toInt().toBigInteger().shl(i*8)
- }
- return value
- }
-
- /**
- * Read a string from the connection.
- *
- * In 9P, strings are represented as a 2-byte integer (the string's size) followed by the actual UTF-8 string. The
- * null terminator is forbidden in 9P messages.
- *
- * @return the string.
- * @throws java.io.IOException if the message could not be correctly received.
- */
- private fun readString(): String {
- val length = readInteger(2u).toShort().toUShort()
- val rawString = this.tl.receive(length.toULong())
- return String(ByteArray(rawString.size) { i -> rawString[i].toByte() })
- }
-
- /**
- * Read a message size, type, and tag.
- *
- * @return A triple in which the first element is the message size in bytes, the second is the message type as a
- * [NinePMessageType] constant, and the third element is the message tag.
- * @throws java.io.IOException if the message could not be correctly received.
- */
- private fun readSizeTypeTag(): Triple<UInt, NinePMessageType, UShort> {
- return Triple(
- readInteger(4u).toInt().toUInt(),
- NinePMessageType.fromByte(readInteger(1u).toByte().toUByte()),
- readInteger(2u).toShort().toUShort()
- )
- }
-
- /**
- * 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.
- * @throws java.io.IOException if the message could not be correctly received.
- */
- private fun waitForTag(tag: UShort): Pair<UInt, NinePMessageType> {
- var s = 0u
- var ty: NinePMessageType? = null
- var ta: UShort
- var found = false
- while (!found) {
- val stt = readSizeTypeTag()
- s = stt.first
- ty = stt.second
- ta = stt.third
-
- if (ta == tag) {
- found = true
- } else {
- // discard?
- }
- }
- 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.
- * @throws java.io.IOException if the message could not be correctly received.
- */
- private fun readError(): Pair<UShort, String> {
- val tag = readInteger(2u).toInt().toUShort()
- val error = readString()
- return Pair(tag, error)
- }
-
- /**
- * Send 9P request and check for exceptions or an Rerror response.
- */
- private fun responseError(msg: Message): String? {
- try {
- msg.write(this.tl)
- } catch (ex: Exception) {
- return "Exception thrown while sending message: (" + ex.javaClass.toString() + ") " + ex.message
- }
- val se = waitForTag(msg.tag)
- if (se.second == NinePMessageType.RERROR) {
- val error = readError()
- return error.second
- }
- return null
- }
-
override fun version(msize: UInt, version: String): String? {
val msg = Message(NinePMessageType.TVERSION, this.NOTAG, listOf("msize", "version"),
mapOf(