diff options
author | Edoardo La Greca | 2025-08-09 19:30:21 +0200 |
---|---|---|
committer | Edoardo La Greca | 2025-08-09 19:30:21 +0200 |
commit | 31c4a211c483363bd254d41c3451e98116b05c4a (patch) | |
tree | d15d4b77d65fe6a250b113ee5b5be395ba8bf6c4 /src/main/kotlin/Connection.kt | |
parent | 5316ed0c6e4200195c6031651e285f61bb1424ab (diff) |
remove fid and qid management from Connection and return them in ProtocolTranslator methods
Diffstat (limited to 'src/main/kotlin/Connection.kt')
-rw-r--r-- | src/main/kotlin/Connection.kt | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt index 1aeb4b1..9b5af33 100644 --- a/src/main/kotlin/Connection.kt +++ b/src/main/kotlin/Connection.kt @@ -2,10 +2,8 @@ import except.MsizeValueTooBigException import except.RErrorException import except.UnaccessibleFileException import except.UnknownVersionException -import java.io.File import java.io.IOException import java.math.BigInteger -import kotlin.io.path.Path /** * This class represents a 9P connection. It provides a practical implementation with networking to the 9P methods @@ -36,11 +34,6 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { */ private var maxSize: UInt = 0u - /** - * Info about remote paths. - */ - val pathInfo: PathInfo = PathInfo() - // 9P constants. val DEFAULT_VERSION = "9P2000" val NOTAG = 0.toUShort().inv() @@ -123,7 +116,7 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { val imsg = checkedInMessage(omsg.tag) } - override fun attach(fid: UInt, afid: UInt, uname: String, aname: String) { + override fun attach(fid: UInt, afid: UInt, uname: String, aname: String): QID { val omsg = OutMessage(NinePMessageType.TATTACH, this.tagGen.generate(), listOf("fid", "afid", "uname", "aname"), mapOf( "fid" to BigInteger(fid.toString()), @@ -141,10 +134,10 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { imsg.applyField(InMessage.Field("qid", InMessage.Field.Type.RAW, 13u)) val qid = QID(imsg.fieldsRaw["qid"]!!.toList()) - this.pathInfo.addPath(PathInfo.Path(aname.split("/"), fid, qid)) + return qid } - override fun walk(fid: UInt, newfid: UInt, wname: List<String>) { + override fun walk(fid: UInt, newfid: UInt, wname: List<String>): List<QID> { val nwname = wname.size val omsg = OutMessage(NinePMessageType.TWALK, this.tagGen.generate(), listOf("fid", "newfid", "nwname"), mapOf( @@ -165,7 +158,7 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { imsg.applyField(InMessage.Field("nwqid", InMessage.Field.Type.INTEGER, 2u)) val nwqid = imsg.fieldsInt["nwqid"]!!.toInt() if (nwqid < nwname) { - throw UnaccessibleFileException(wname.slice(0..nwqid).joinToString(separator = "/")) + throw UnaccessibleFileException(wname.slice(0..nwqid)) } imsg.applyField(InMessage.Field("qids", InMessage.Field.Type.RAW, (nwqid * 13).toUInt())) val rawQids = imsg.fieldsRaw["qids"]!! @@ -176,12 +169,7 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { val rawQid = rawQids.slice(start..end) qids += QID(rawQid) } - - for (i in 0..<nwname) { - this.pathInfo.addPath(PathInfo.Path(wname.slice(0..<i), null, qids[i])) - } - this.pathInfo.removeFID(fid) - this.pathInfo.addPath(PathInfo.Path(wname, newfid, qids.last())) + return qids.toList() } override fun open(fid: UInt, mode: FileMode): Pair<QID, UInt> { |