diff options
author | bptato <nincsnevem662@gmail.com> | 2023-02-13 15:38:51 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-02-13 15:38:51 +0100 |
commit | e4ecff6f3ff5e0ab617627f8637e4c3179cc4caf (patch) | |
tree | d2efd123885e835fc18812bf17a22984690d5b49 /src/buffer | |
parent | 81290d7e577701f37a1c4559f0a7777b904e7ed7 (diff) | |
download | chawan-e4ecff6f3ff5e0ab617627f8637e4c3179cc4caf.tar.gz |
buffer: adapt onload to PosixStream and SocketStream
Diffstat (limited to 'src/buffer')
-rw-r--r-- | src/buffer/buffer.nim | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim index 51c09616..04304afb 100644 --- a/src/buffer/buffer.nim +++ b/src/buffer/buffer.nim @@ -652,21 +652,20 @@ proc onload(buffer: Buffer) = try: buffer.sstream.setPosition(op + buffer.available) let n = buffer.istream.readData(addr s[0], buffer.readbufsize) - assert n != 0 - s.setLen(n) - buffer.sstream.setPosition(op) - if buffer.readbufsize < BufferSize: - buffer.readbufsize = min(BufferSize, buffer.readbufsize * 2) - buffer.available += s.len - case buffer.contenttype - of "text/html": - res.bytes = buffer.available - else: - buffer.do_reshape() - buffer.resolveTask(LOAD, res) - except EOFError: - res.atend = true - buffer.finishLoad() + if n != 0: # n can be 0 if we get EOF. (in which case we shouldn't reshape unnecessarily.) + s.setLen(n) + buffer.sstream.setPosition(op) + if buffer.readbufsize < BufferSize: + buffer.readbufsize = min(BufferSize, buffer.readbufsize * 2) + buffer.available += s.len + case buffer.contenttype + of "text/html": + res.bytes = buffer.available + else: + buffer.do_reshape() + if buffer.istream.atEnd(): + res.atend = true + buffer.finishLoad() buffer.resolveTask(LOAD, res) except ErrorAgain, ErrorWouldBlock: if buffer.readbufsize > 1: |