diff --git a/libp2p/stream/chronosstream.nim b/libp2p/stream/chronosstream.nim index c1bca76..2ebe529 100644 --- a/libp2p/stream/chronosstream.nim +++ b/libp2p/stream/chronosstream.nim @@ -21,12 +21,12 @@ proc newChronosStream*(client: StreamTransport): ChronosStream = result.client = client result.closeEvent = newAsyncEvent() - template withExceptions(body: untyped) = try: body except TransportIncompleteError: - raise newLPStreamIncompleteError() + # for all intents and purposes this is an EOF + raise newLPStreamEOFError() except TransportLimitError: raise newLPStreamLimitError() except TransportUseClosedError: @@ -60,9 +60,12 @@ method write*(s: ChronosStream, msg: seq[byte]) {.async.} = return withExceptions: - # Returns 0 sometimes when write fails - but there's not much we can do here? - if (await s.client.write(msg)) != msg.len: - raise (ref LPStreamError)(msg: "Write couldn't finish writing") + var writen = 0 + while not s.client.closed and writen < msg.len: + writen += await s.client.write(msg[writen..