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 != {})