From b5d2745d075d20e5db2aae720cdaf2f821f1c40d Mon Sep 17 00:00:00 2001 From: Alexander Guryanov Date: Thu, 24 Oct 2024 12:41:45 +0300 Subject: [PATCH] v8.3.5: improved sockdrive read cache --- package.json | 4 ++-- src/frame/stats-frame.tsx | 2 +- src/sidebar/sidebar.tsx | 1 - src/sockdrive | 2 +- src/ui.tsx | 2 +- src/window/dos/dos-runtime.tsx | 9 ++++++-- src/ws/ws-sockdrive.ts | 8 ++++--- src/ws/ws-transport-layer.ts | 40 +++++++++++++++++++--------------- yarn.lock | 8 +++---- 9 files changed, 44 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 3c510eb8..dff74442 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-dos", - "version": "8.3.4", + "version": "8.3.5", "description": "Full-featured DOS player with multiple emulator backends", "type": "module", "keywords": [ @@ -37,7 +37,7 @@ "@typescript-eslint/parser": "^6.20.0", "autoprefixer": "^10.4.17", "daisyui": "^3.9.3", - "emulators": "8.3.1", + "emulators": "8.3.2", "eslint": "^8.56.0", "eslint-config-google": "^0.14.0", "postcss": "^8.4.33", diff --git a/src/frame/stats-frame.tsx b/src/frame/stats-frame.tsx index 39171489..7adbdd3a 100644 --- a/src/frame/stats-frame.tsx +++ b/src/frame/stats-frame.tsx @@ -79,7 +79,7 @@ export function StatsFrame() { {driveInfo.map((info, i) => { return HDD { i == 0 ? "C:" : "D:"} - {info.drive} {info.write ? " RW" : " RO" } + {info.drive.replace("/", " ")} {info.write ? " RW" : " RO" } ; })} diff --git a/src/sidebar/sidebar.tsx b/src/sidebar/sidebar.tsx index a0852d87..57f48088 100644 --- a/src/sidebar/sidebar.tsx +++ b/src/sidebar/sidebar.tsx @@ -13,7 +13,6 @@ import { SaveButtons } from "./save-buttons"; export function SideBar(props: {}) { const window = useSelector((state: State) => state.ui.window); const editor = useSelector((state: State) => state.ui.editor); - const backend = useSelector((state: State) => state.dos.backend); const kiosk = useSelector((state: State) => state.ui.kiosk); const networking = !useSelector((state: State) => state.ui.noNetworking); diff --git a/src/sockdrive b/src/sockdrive index e4d1d354..78b9382a 160000 --- a/src/sockdrive +++ b/src/sockdrive @@ -1 +1 @@ -Subproject commit e4d1d354819dd5c59eb83831613c08aee6451744 +Subproject commit 78b9382ae6774d67445fdbdb59b52f487cae8171 diff --git a/src/ui.tsx b/src/ui.tsx index 1bb164fc..db1f7482 100644 --- a/src/ui.tsx +++ b/src/ui.tsx @@ -87,7 +87,7 @@ function Toast() { class="shrink-0 w-6 h-6"> {path} - {toast} + {toast} ; } diff --git a/src/window/dos/dos-runtime.tsx b/src/window/dos/dos-runtime.tsx index 4654ad67..222b4b9e 100644 --- a/src/window/dos/dos-runtime.tsx +++ b/src/window/dos/dos-runtime.tsx @@ -35,6 +35,7 @@ function useLog(ci: CommandInterface): void { const t = useT(); useEffect(() => { const preloadProgress: { [drive: string]: number } = {}; + const isFork: { [drive: string]: boolean } = {}; ci.events().onMessage((msgType, ...args: string[]) => { if (msgType === "error" && args[0]?.startsWith("[panic]")) { dispatch(uiSlice.actions.showToast({ @@ -45,7 +46,10 @@ function useLog(ci: CommandInterface): void { const drive = args[0].substring(args[0].indexOf(" ") + 1, args[0].indexOf(",")); dispatch(uiSlice.actions.cloudSaves(false)); if (args[0]?.indexOf("write=") !== -1) { - console.log("drive", drive, "config:", args[0]); + const name = drive.substring(drive.indexOf("/") + 1); + if (name.startsWith("@")) { + isFork[drive.substring(drive.indexOf(".", drive.indexOf("/")) + 1)] = true; + } dispatch(dosSlice.actions.addSockdriveInfo({ drive, write: args[0]?.indexOf("write=false") === -1, @@ -57,9 +61,10 @@ function useLog(ci: CommandInterface): void { preloadProgress[drive] = rest; } + const name = drive.substring(drive.indexOf("/") + 1); dispatch(uiSlice.actions.showToast({ message: t("preloading_sockdrive") + " " + - drive.substring(drive.indexOf("/") + 1) + " — " + + (isFork[name] ? "@" + name : name) + " — " + (Math.round(preloadProgress[drive] - rest) / 1024 / 1024).toFixed(2) + "/" + (Math.round(preloadProgress[drive] / 1024 / 1024)) + "Mb", long: true, diff --git a/src/ws/ws-sockdrive.ts b/src/ws/ws-sockdrive.ts index d437e36a..2e9f0e0e 100644 --- a/src/ws/ws-sockdrive.ts +++ b/src/ws/ws-sockdrive.ts @@ -18,7 +18,8 @@ export interface ReadResponse { } export function createSockdrive( - onOpen: (drive: string, read: boolean, write: boolean, imageSize: number) => void, + onOpen: (drive: string, read: boolean, write: boolean, imageSize: number, + realOwner: string, realDrive: string) => void, onError: (e: Error) => void, onPreloadProgress: (drive: string, restBytes: number) => void, onPayload: (owner: string, drive: string, sectorSize: number, @@ -77,10 +78,11 @@ export function createSockdrive( mapping[seq] = new Drive(url, owner, name, token, stats, module, backendCache, true); return new Promise<{ handle: Handle, aheadRange: number }>((resolve, reject) => { const drive = owner + "/" + name; - mapping[seq].onOpen((read, write, imageSize, aheadRange) => { + mapping[seq].onOpen((read, write, imageSize, aheadRange, realOwner, realDrive) => { memory[seq] = new Uint8Array(sectorSize /* write */ + sectorSize * aheadRange); module.HEAPU8 = memory[seq]; - onOpen(drive, read, write, imageSize); + onOpen(drive, read, write, imageSize, + realOwner, realDrive); resolve({ handle: seq, aheadRange, diff --git a/src/ws/ws-transport-layer.ts b/src/ws/ws-transport-layer.ts index 0898b1a6..2dd2164b 100644 --- a/src/ws/ws-transport-layer.ts +++ b/src/ws/ws-transport-layer.ts @@ -58,6 +58,7 @@ export class WsTransportLayer implements TransportLayer { this.onSockdrivePreloadProgress.bind(this), this.onSockdrivePayload.bind(this)); private sockdriveSeq = 1; + private version = 0; private handler: MessageHandler = () => {/**/}; @@ -128,7 +129,8 @@ export class WsTransportLayer implements TransportLayer { const message = serverMessageEnum[id]; switch (message) { case "ws-ready": { - this.onInit((payload && payload[0] && payload.length > 0) ? payload[0][0] : 0); + this.version = (payload && payload[0] && payload.length > 0) ? payload[0][0] : 0; + this.onInit(this.version); this.handler(message, {}); } break; case "ws-server-ready": @@ -371,7 +373,7 @@ export class WsTransportLayer implements TransportLayer { const owner = textDecoder.decode(payload[0]!); const name = textDecoder.decode(payload[1]!); this.onSockdriveOpen(owner + "/" + name, true, - payload[2]![0] === 1, this.readUint32(payload[2]!, 1)); + payload[2]![0] === 1, this.readUint32(payload[2]!, 1), owner, name); } break; default: console.log("WARN! Unhandled server non standard message", id, payload); @@ -495,10 +497,12 @@ export class WsTransportLayer implements TransportLayer { this.sendMessageToSocket("wc-exit"); } - onSockdriveOpen(drive: string, read: boolean, write: boolean, imageSize: number) { + onSockdriveOpen(drive: string, read: boolean, write: boolean, imageSize: number, + realOwner: string, realDrive: string) { this.handler("ws-log", { tag: "worker", - message: "sockdrive: " + drive + ", read=" + read + ", write=" + write + + message: "sockdrive: " + (realOwner ? realOwner + "/" + realDrive : drive) + + ", read=" + read + ", write=" + write + ", imageSize=" + Math.round(imageSize / 1024 / 1024) + "Mb", }); } @@ -519,20 +523,22 @@ export class WsTransportLayer implements TransportLayer { onSockdrivePayload(owner: string, drive: string, sectorSize: number, aheadRange: number, sectors: number[], row: Uint8Array) { - const sectorsPayload = new Uint8Array(sectors.length * 4 + 2 * 4); - let offset = 0; - for (const sector of sectors) { - offset = this.writeUint32(sectorsPayload, sector, offset); + if (this.version > 3) { + const sectorsPayload = new Uint8Array(sectors.length * 4 + 2 * 4); + let offset = 0; + for (const sector of sectors) { + offset = this.writeUint32(sectorsPayload, sector, offset); + } + offset = this.writeUint32(sectorsPayload, sectorSize, offset); + this.writeUint32(sectorsPayload, aheadRange, offset); + + this.sendMessageToSocket(106 /* wc-sockdrive-cache */, + textEncoder.encode(owner), + textEncoder.encode(drive), + sectorsPayload, + row, + ); } - offset = this.writeUint32(sectorsPayload, sectorSize, offset); - this.writeUint32(sectorsPayload, aheadRange, offset); - - this.sendMessageToSocket(106 /* wc-sockdrive-cache */, - textEncoder.encode(owner), - textEncoder.encode(drive), - sectorsPayload, - row, - ); } } diff --git a/yarn.lock b/yarn.lock index cd1c2f07..f4a4bca3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1174,10 +1174,10 @@ electron-to-chromium@^1.4.648: resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.653.tgz#832ab25e80ad698ac09c1ca547bd9ee6cce7df10" integrity sha512-wA2A2LQCqnEwQAvwADQq3KpMpNwgAUBnRmrFgRzHnPhbQUFArTR32Ab46f4p0MovDLcg4uqd4nCsN2hTltslpA== -emulators@8.3.1: - version "8.3.1" - resolved "https://registry.yarnpkg.com/emulators/-/emulators-8.3.1.tgz#25788315876b4176bb9aa0ad929707a59f7f3537" - integrity sha512-rhEVIGKPSINIdCp68Y4Udwofu+nBbfT2eSJNJ/xQiI6wdoV1aIziyROkk6WySM0p5YZ3pu256YuqE3mMNuzMJQ== +emulators@8.3.2: + version "8.3.2" + resolved "https://registry.yarnpkg.com/emulators/-/emulators-8.3.2.tgz#bc1b1007fef87c9ab0902f3dffe0e8f6cc9eaca9" + integrity sha512-MbQS+UEv+/EZsT7Y9MCgW8iOpNLLzrR3oZJtpxTnDFpUUN59n3T9YvmyXqNJrQW65BbF2Q4j0lCvv9/mY8kuaw== entities@^4.2.0: version "4.5.0"