call write until all is written out

This commit is contained in:
Dmitriy Ryajov 2020-05-11 11:36:40 -06:00
parent 42ae8589fb
commit 2d1b05e827
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4

View File

@ -60,9 +60,9 @@ method write*(s: ChronosStream, msg: seq[byte]) {.async.} =
return return
withExceptions: withExceptions:
# Returns 0 sometimes when write fails - but there's not much we can do here? var writen = 0
if (await s.client.write(msg)) != msg.len: while (writen < msg.len):
raise (ref LPStreamError)(msg: "Write couldn't finish writing") writen += await s.client.write(msg[writen..<msg.len]) # TODO: does the slice create a copy here?
method closed*(s: ChronosStream): bool {.inline.} = method closed*(s: ChronosStream): bool {.inline.} =
result = s.client.closed result = s.client.closed