diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-26 17:06:46 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-26 17:13:04 +0100 |
commit | d74933cf04e79e08f3623c6dd1c112fa26a7a4df (patch) | |
tree | 28f7b49fdcf72c4d377fe51a3f6bc2c4984d9ef1 /src/server | |
parent | 973e8f942855fe9a17f0245948984bf9841f9ffa (diff) | |
download | chawan-d74933cf04e79e08f3623c6dd1c112fa26a7a4df.tar.gz |
buffer: clean up onload, fix console update
* reduce onload result size to a single int * clean up mess that was the container onload handler This fixes automatic refresh in console. Before, the client would only request a screen update after receiving the number of bytes read, but before the screen was actually reshaped (which obviously resulted in a race condition). Now, "I've reshaped the document" is a separate response (and is the only occasion where the screen is updated before the final render).
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/buffer.nim | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim index 6f8beb34..cfaa8b12 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -1137,16 +1137,15 @@ proc finishLoad(buffer: Buffer): EmptyPromise = buffer.loader.removeCachedURL($buffer.request.url) return buffer.loadResources() -type LoadResult* = tuple[ - atend: bool, - lines: int, - bytes: int -] - -proc load*(buffer: Buffer): LoadResult {.proxy, task.} = +# Returns: +# * -1 if loading is done +# * -2 if the page was partially rendered +# * a positive number for just reporting the number of bytes loaded. +proc load*(buffer: Buffer): int {.proxy, task.} = if buffer.state == bsLoaded: - return (true, buffer.lines.len, -1) + return -1 else: + # will be resolved in onload buffer.savetask = true proc resolveTask[T](buffer: Buffer, cmd: BufferCommand, res: T) = @@ -1161,12 +1160,11 @@ proc resolveTask[T](buffer: Buffer, cmd: BufferCommand, res: T) = buffer.pstream.flush() proc onload(buffer: Buffer) = - var res: LoadResult = (false, buffer.lines.len, -1) case buffer.state of bsConnecting: assert false of bsLoadingResources, bsLoaded: - buffer.resolveTask(LOAD, res) + buffer.resolveTask(LOAD, -1) return of bsLoadingPage: discard @@ -1178,7 +1176,6 @@ proc onload(buffer: Buffer) = if not reprocess: n = buffer.istream.recvData(addr iq[0], iq.len) buffer.bytesRead += n - res.lines = buffer.lines.len if n != 0: if not buffer.processData(iq.toOpenArray(0, n - 1)): if not buffer.firstBufferRead: @@ -1188,26 +1185,23 @@ proc onload(buffer: Buffer) = continue buffer.firstBufferRead = true reprocess = false - res.bytes = buffer.bytesRead - res.lines = buffer.lines.len else: # EOF - res.atend = true buffer.finishLoad().then(proc() = buffer.do_reshape() - res.lines = buffer.lines.len buffer.state = bsLoaded buffer.document.readyState = rsComplete buffer.dispatchLoadEvent() - buffer.resolveTask(LOAD, res) + buffer.resolveTask(LOAD, -1) ) return # skip incr render - buffer.resolveTask(LOAD, res) + buffer.resolveTask(LOAD, buffer.bytesRead) except ErrorAgain: break # incremental rendering: only if we cannot read the entire stream in one # pass #TODO this could be improved buffer.do_reshape() + buffer.resolveTask(LOAD, -2) proc getTitle*(buffer: Buffer): string {.proxy.} = if buffer.document != nil: |