add closed() procedure to check if transport is closed.

This commit is contained in:
cheatfate 2018-07-13 11:24:52 +03:00
parent aa15313aa8
commit 693783b36b
2 changed files with 8 additions and 0 deletions

View File

@ -665,3 +665,7 @@ proc getMessage*(transp: DatagramTransport): seq[byte] =
proc getUserData*[T](transp: DatagramTransport): T {.inline.} =
## Obtain user data stored in ``transp`` object.
result = cast[T](transp.udata)
proc closed*(transp: DatagramTransport): bool {.inline.} =
## Returns ``true`` if transport in closed state.
result = ({ReadClosed, WriteClosed} * transp.state != {})

View File

@ -1213,3 +1213,7 @@ proc close*(transp: StreamTransport) =
transp.state.incl({WriteClosed, ReadClosed})
transp.future.complete()
GC_unref(transp)
proc closed*(transp: StreamTransport): bool {.inline.} =
## Returns ``true`` if transport in closed state.
result = ({ReadClosed, WriteClosed} * transp.state != {})