From 693783b36b5a6f5251ba22150a56b4c27b353508 Mon Sep 17 00:00:00 2001 From: cheatfate Date: Fri, 13 Jul 2018 11:24:52 +0300 Subject: [PATCH] add closed() procedure to check if transport is closed. --- asyncdispatch2/transports/datagram.nim | 4 ++++ asyncdispatch2/transports/stream.nim | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/asyncdispatch2/transports/datagram.nim b/asyncdispatch2/transports/datagram.nim index d721c536..4ed1ab7b 100644 --- a/asyncdispatch2/transports/datagram.nim +++ b/asyncdispatch2/transports/datagram.nim @@ -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 != {}) diff --git a/asyncdispatch2/transports/stream.nim b/asyncdispatch2/transports/stream.nim index 2f113536..4ad1af7b 100644 --- a/asyncdispatch2/transports/stream.nim +++ b/asyncdispatch2/transports/stream.nim @@ -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 != {})