diff options
author | Araq <rumpf_a@web.de> | 2019-11-12 17:04:59 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-11-13 23:29:21 +0100 |
commit | eea0cb07cfcebcb5be9e1a942834c7ed675579b9 (patch) | |
tree | 6dfef9dcdb3848926630323587bb036a3a009053 /lib | |
parent | a1e7bf81b334c3384e8f5af9d2e244225211b2b2 (diff) | |
download | Nim-eea0cb07cfcebcb5be9e1a942834c7ed675579b9.tar.gz |
async: cleaner solution that avoids GC_ref on strings which doesn't exist for --gc:arc
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/asyncdispatch.nim | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 38946e82f..a99a465f8 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -1830,20 +1830,19 @@ proc accept*(socket: AsyncFD, retFut.complete(future.read.client) return retFut +proc keepAlive(x: string) = + discard "mark 'x' as escaping so that it is put into a closure for us to keep the data alive" + proc send*(socket: AsyncFD, data: string, flags = {SocketFlag.SafeDisconn}): owned(Future[void]) = ## Sends ``data`` to ``socket``. The returned future will complete once all ## data has been sent. var retFuture = newFuture[void]("send") - var copiedData = data - GC_ref(copiedData) # we need to protect data until send operation is completed - # or failed. - - let sendFut = socket.send(addr copiedData[0], data.len, flags) + let sendFut = socket.send(unsafeAddr data[0], data.len, flags) sendFut.callback = proc () = - GC_unref(copiedData) + keepAlive(data) if sendFut.failed: retFuture.fail(sendFut.error) else: |