diff options
author | bptato <nincsnevem662@gmail.com> | 2023-06-07 13:15:17 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-06-07 13:19:02 +0200 |
commit | d78298ae3369374bf7bf31592513d112c75a9601 (patch) | |
tree | e8daf184adb0b09d48d53bf123f23a5d2a7b8d86 /src/ips | |
parent | c15d04041b1b8660000a1517b9d4bfc06f2cb490 (diff) | |
download | chawan-d78298ae3369374bf7bf31592513d112c75a9601.tar.gz |
Clean up stream error handling
* sread now raises EOFError if readData returns too few bytes * buffer handleError ignores unregistered fds like client * client handleError ignores unregistered fds like buffer
Diffstat (limited to 'src/ips')
-rw-r--r-- | src/ips/serialize.nim | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/ips/serialize.nim b/src/ips/serialize.nim index c2a6f5a6..beab3a5e 100644 --- a/src/ips/serialize.nim +++ b/src/ips/serialize.nim @@ -80,7 +80,8 @@ proc swrite*(stream: Stream, n: SomeNumber) = stream.write(n) proc sread*(stream: Stream, n: var SomeNumber) = - stream.read(n) + if stream.readData(addr n, sizeof(n)) < sizeof(n): + raise newException(EOFError, "eof") func slen*(n: SomeNumber): int = return sizeof(n) @@ -122,7 +123,9 @@ proc sread*(stream: Stream, s: var string) = var len: int stream.sread(len) if len > 0: - stream.readStr(len, s) + s = newString(len) + if stream.readData(addr s[0], len) < len: + raise newException(EOFError, "eof") else: s = "" |