mirror of https://github.com/vacp2p/nim-libp2p.git
await for void features and add closed flag
This commit is contained in:
parent
e13f42f9bb
commit
402067ceae
|
@ -23,12 +23,13 @@ proc newChronosStream*(server: StreamServer,
|
|||
result.client = client
|
||||
result.reader = newAsyncStreamReader(client)
|
||||
result.writer = newAsyncStreamWriter(client)
|
||||
result.closed = false
|
||||
|
||||
method read*(s: ChronosStream, n = -1): Future[seq[byte]] {.async.} =
|
||||
result = await s.reader.read(n)
|
||||
|
||||
method readExactly*(s: ChronosStream, pbytes: pointer, nbytes: int): Future[void] {.async.} =
|
||||
result = s.readExactly(pbytes, nbytes)
|
||||
await s.readExactly(pbytes, nbytes)
|
||||
|
||||
method readLine*(s: ChronosStream, limit = 0, sep = "\r\n"): Future[string] {.async.} =
|
||||
result = await s.reader.readLine(limit, sep)
|
||||
|
@ -40,13 +41,13 @@ method readUntil*(s: ChronosStream, pbytes: pointer, nbytes: int, sep: seq[byte]
|
|||
result = await s.reader.readUntil(pbytes, nbytes, sep)
|
||||
|
||||
method write*(s: ChronosStream, pbytes: pointer, nbytes: int) {.async.} =
|
||||
result = s.writer.write(pbytes, nbytes)
|
||||
await s.writer.write(pbytes, nbytes)
|
||||
|
||||
method write*(s: ChronosStream, msg: string, msglen = -1) {.async.} =
|
||||
result = s.writer.write(msg, msglen)
|
||||
await s.writer.write(msg, msglen)
|
||||
|
||||
method write*(s: ChronosStream, msg: seq[byte], msglen = -1) {.async.} =
|
||||
result = s.writer.write(msg, msglen)
|
||||
await s.writer.write(msg, msglen)
|
||||
|
||||
method close*(s: ChronosStream) {.async.} =
|
||||
await s.reader.closeWait()
|
||||
|
@ -57,3 +58,4 @@ method close*(s: ChronosStream) {.async.} =
|
|||
await s.client.closeWait()
|
||||
s.server.stop()
|
||||
s.server.close()
|
||||
s.closed = true
|
|
@ -26,7 +26,7 @@ method read*(s: Connection, n = -1): Future[seq[byte]] {.async.} =
|
|||
result = await s.stream.read(n)
|
||||
|
||||
method readExactly*(s: Connection, pbytes: pointer, nbytes: int): Future[void] {.async.} =
|
||||
result = s.stream.readExactly(pbytes, nbytes)
|
||||
await s.stream.readExactly(pbytes, nbytes)
|
||||
|
||||
method readLine*(s: Connection, limit = 0, sep = "\r\n"): Future[string] {.async.} =
|
||||
result = await s.stream.readLine(limit, sep)
|
||||
|
@ -38,16 +38,17 @@ method readUntil*(s: Connection, pbytes: pointer, nbytes: int, sep: seq[byte]):
|
|||
result = await s.stream.readUntil(pbytes, nbytes, sep)
|
||||
|
||||
method write*(s: Connection, pbytes: pointer, nbytes: int) {.async.} =
|
||||
result = s.stream.write(pbytes, nbytes)
|
||||
await s.stream.write(pbytes, nbytes)
|
||||
|
||||
method write*(s: Connection, msg: string, msglen = -1) {.async.} =
|
||||
result = s.stream.write(msg, msglen)
|
||||
await s.stream.write(msg, msglen)
|
||||
|
||||
method write*(s: Connection, msg: seq[byte], msglen = -1) {.async.} =
|
||||
result = s.stream.write(msg, msglen)
|
||||
await s.stream.write(msg, msglen)
|
||||
|
||||
method close*(s: Connection) {.async.} =
|
||||
result = s.stream.close()
|
||||
await s.stream.close()
|
||||
s.closed = true
|
||||
|
||||
proc readLp*(s: Connection): Future[seq[byte]] {.async.} =
|
||||
## read lenght prefixed msg
|
||||
|
|
Loading…
Reference in New Issue