diff options
author | bptato <nincsnevem662@gmail.com> | 2023-02-05 17:48:37 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-02-05 17:48:37 +0100 |
commit | 21178cc60e1d4ba3a6780c5691b9cfb5e7908aa8 (patch) | |
tree | 8db0946d00b3f60600b8177d2df3914b227125e1 /src/io | |
parent | 7e9408b80a5a8b12710ce8b14a4ee78900ee2be4 (diff) | |
download | chawan-21178cc60e1d4ba3a6780c5691b9cfb5e7908aa8.tar.gz |
Slightly improve request api (less crashes)
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/loader.nim | 7 | ||||
-rw-r--r-- | src/io/posixstream.nim | 5 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/io/loader.nim b/src/io/loader.nim index 4931d40b..d96d1a5a 100644 --- a/src/io/loader.nim +++ b/src/io/loader.nim @@ -106,10 +106,9 @@ proc runFileLoader*(fd: cint, config: LoaderConfig) = of QUIT: stream.close() break - except EOFError: - # End-of-file, quit. - break - stream.close() + except IOError: + # End-of-file, broken pipe, or something. + stream.close() curl_global_cleanup() ssock.close() quit(0) diff --git a/src/io/posixstream.nim b/src/io/posixstream.nim index fa0a35ca..10fd2237 100644 --- a/src/io/posixstream.nim +++ b/src/io/posixstream.nim @@ -33,6 +33,7 @@ proc raisePosixIOError*() = proc psReadData(s: Stream, buffer: pointer, len: int): int = assert len != 0 let s = cast[PosixStream](s) + let wasend = s.isend while result < len: let n = read(s.fd, cast[pointer](cast[int](buffer) + result), len) if n < 0: @@ -44,7 +45,9 @@ proc psReadData(s: Stream, buffer: pointer, len: int): int = break result += n if result == 0: - raise newException(EOFError, "eof") + if wasend: + raise newException(EOFError, "eof") + s.isend = true if result == -1: raisePosixIOError() |