about summary refs log tree commit diff stats
path: root/src/server
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-13 16:48:58 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-13 16:48:58 +0100
commitaadbaffac2430abf01a849b1f7bbfb154c27d229 (patch)
treeea88c5a91af1544dddd26d5d41e200dc4907936d /src/server
parent492a9e7cf80ae8e26b03602b5996f471c5edf4be (diff)
downloadchawan-aadbaffac2430abf01a849b1f7bbfb154c27d229.tar.gz
loader: fixes & improvements
* factor out pushBuffer to make loadFromCache async
* fix incorrect cache path
* replace rewind with loadFromCache (it does the same thing except
  actually works)
* remove rewindImpl callback, rewind in buffer instead
Diffstat (limited to 'src/server')
-rw-r--r--src/server/buffer.nim39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index ef7afc44..0a144fd4 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -632,14 +632,15 @@ proc do_reshape(buffer: Buffer) =
     buffer.lines = renderDocument(styledRoot, buffer.attrs)
     buffer.prevstyled = styledRoot
   else:
-    buffer.lines.renderStream(buffer.srenderer)
+    discard
+    #buffer.lines.renderStream(buffer.srenderer) TODO remove?
 
-proc processData(buffer: Buffer) =
+proc processData(buffer: Buffer): bool =
   if buffer.ishtml:
-    buffer.htmlParser.parseAll()
+    result = buffer.htmlParser.parseAll()
     buffer.document = buffer.htmlParser.builder.document
   else:
-    buffer.lines.renderStream(buffer.srenderer)
+    result = buffer.lines.renderStream(buffer.srenderer, debug = buffer.url.pathname != "console")
 
 proc windowChange*(buffer: Buffer, attrs: WindowAttributes) {.proxy.} =
   buffer.attrs = attrs
@@ -706,24 +707,20 @@ type ConnectResult* = object
   charset*: Charset
 
 proc rewind(buffer: Buffer): bool =
-  if buffer.loader.rewind(buffer.fd):
-    return true
   let request = newRequest(buffer.url, fromcache = true)
   let response = buffer.loader.doRequest(request)
-  if response.body != nil:
-    buffer.selector.unregister(buffer.fd)
-    buffer.loader.unregistered.add(buffer.fd)
-    buffer.istream.close()
-    buffer.istream = response.body
-    buffer.fd = response.body.fd
-    buffer.selector.registerHandle(buffer.fd, {Read}, 0)
-    return true
-  return false
+  if response.body == nil:
+    return false
+  buffer.selector.unregister(buffer.fd)
+  buffer.loader.unregistered.add(buffer.fd)
+  buffer.istream.close()
+  buffer.istream = response.body
+  buffer.fd = response.body.fd
+  buffer.selector.registerHandle(buffer.fd, {Read}, 0)
+  return true
 
 proc setHTML(buffer: Buffer, ishtml: bool) =
   buffer.ishtml = ishtml
-  let rewindImpl = proc() =
-    doAssert buffer.rewind()
   if ishtml:
     let factory = newCAtomFactory()
     buffer.factory = factory
@@ -752,7 +749,6 @@ proc setHTML(buffer: Buffer, ishtml: bool) =
       buffer.window,
       buffer.url,
       buffer.factory,
-      rewindImpl = rewindImpl,
       buffer.charsets,
       seekable = true
     )
@@ -762,8 +758,7 @@ proc setHTML(buffer: Buffer, ishtml: bool) =
     buffer.quirkstyle = quirk.parseStylesheet(factory)
     buffer.userstyle = parseStylesheet(buffer.config.userstyle, factory)
   else:
-    buffer.srenderer = newStreamRenderer(buffer.sstream, buffer.charsets,
-      rewindImpl)
+    buffer.srenderer = newStreamRenderer(buffer.sstream, buffer.charsets)
 
 proc connect*(buffer: Buffer): ConnectResult {.proxy.} =
   if buffer.connected:
@@ -1103,7 +1098,9 @@ proc onload(buffer: Buffer) =
         buffer.sstream.data.setLen(n)
       if n != 0:
         buffer.available += n
-        buffer.processData()
+        if not buffer.processData():
+          if buffer.rewind():
+            continue
         res.bytes = buffer.available
       res.lines = buffer.lines.len
       if buffer.istream.atEnd():