From 2760bfe13b708c4f344de7fbb489553f023e153a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net> Date: Sat, 28 Dec 2024 14:11:10 -0500 Subject: [PATCH] Fix syncterm_cache.js It was badly broken, especially with large files... we now don't try console.write() unless there's enough space in console.output_buffer_space. On my system (debug build of Synchronet), the most I can push through console.write() over telnet is about 1.9MB/s. My release build of SyncTERM can consume about 4MB/s of string data, so Synchronet is the choke point in my setup here. (SSH is much worse) My super-cool demo thing ends up needing about 90 seconds to preload all the cache stuff, so it's simply not useable, even locally. :( If I use client.socket.send(), I can unlock the Synchronet throughput, but I can't remember if client.socket is the passthru socket with SSH or not... and there's no way to synchronize the socket with the console at the end of the send (console has flush(), Socket doesn't, and even if it did, it wouldn't flush through to the output buffer). --- exec/load/syncterm_cache.js | 43 +++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/exec/load/syncterm_cache.js b/exec/load/syncterm_cache.js index 228e0f85d1..de52169c84 100644 --- a/exec/load/syncterm_cache.js +++ b/exec/load/syncterm_cache.js @@ -1,4 +1,4 @@ -function SyncTERMCache = { +function SyncTERMCache() { this.supported = this.supports_syncterm_cache(); }; @@ -63,7 +63,11 @@ SyncTERMCache.prototype.upload = function (fname, cache_fname) { if (cache_fname === undefined) cache_fname = fname; - var path = js.exec_dir + '/' + fname; + var path; + if (fname[0] != '/' && fname[1] != ':') + path = js.exec_dir + '/' + fname; + else + path = fname; if (this.supported === undefined) this.supported = this.supports_syncterm_cache(); if (!this.supported) @@ -71,27 +75,48 @@ SyncTERMCache.prototype.upload = function (fname, cache_fname) // Read file MD5 var f = new File(path); + if (!f.open("rb", true)) + return false; var hash = f.md5_hex; - if (typeof hash !== 'string') + if (typeof hash !== 'string') { + f.close(); return false; - if (hash.length != 32) + } + if (hash.length != 32) { + f.close(); return false; + } // Check for the file in the cache... - console.write('\x1b_SyncTERM:C;L;cache_fname\x1b\\'); + console.write('\x1b_SyncTERM:C;L;'+cache_fname+'\x1b\\'); var lst = read_apc(); var idx = lst.indexOf('\n' + cache_fname + '\t'); if (idx !== -1) { idx += 2; idx += cache_fname.length; - if (hash == lst.substr(idx, idx + 32)) + if (hash == lst.substr(idx, idx + 32)) { + f.close(); return true; + } } - if (!f.open("rb", true)) - return false; f.base64 = true; - var buf = "\x1b_SyncTERM:C;S;"+cache_fname+";"+f.read()+"\x1b\\"; + console.write("\x1b_SyncTERM:C;S;"+cache_fname+";"); + var buf; + while((!js.terminated) && bbs.online) { + var rdlen = console.output_buffer_space; + if (rdlen < 4) { + mswait(1); + continue; + } + rdlen = parseInt(rdlen / 4, 10); + rdlen *= 3; + buf = f.read(rdlen); + if (buf.length === 0) + break; + console.write(buf); + } + console.write("\x1b\\"); f.close(); return true; } -- GitLab