Merge pull request #6 from 2-towns/chore/destroy-mapping-cleanup

chore: destroyMapping cleanup
This commit is contained in:
Arnaud 2026-06-05 11:04:35 +04:00 committed by GitHub
commit ab79787bcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 10 deletions

8
api.md
View File

@ -108,10 +108,10 @@ Returns an error if no NAT device is found, the mapping fails, or the timeout ex
proc destroyMapping*(id: cint)
```
Removes a mapping. Must be called exactly once after a successful `createMapping`,
otherwise the mapping's internal handle is leaked for the lifetime of the process.
Calling it again, or with an unknown `id`, is a safe no-op. `cleanup` also releases
any mappings still active.
Removes a mapping. Call it after a successful `createMapping`, otherwise the
mapping's internal handle is leaked for the lifetime of the process. Calling it
again, or with an unknown `id`, is a safe no-op. `cleanup` also releases any
mappings still active.
### hasMapping

View File

@ -274,11 +274,10 @@ proc createMapping*(
return err("plum: mapping " & $id & " failed")
proc destroyMapping*(id: cint) =
## Must be called exactly once after a successful createMapping.
## Safe to call again or on an unknown id
withSafeLock:
if id notin activeMappings:
return
## Releases a mapping created by createMapping. Safe to call again or
## with an unknown id.
# libplum locks internally and ignores unknown ids: no wrapper-side
# bookkeeping needed.
discard plum_destroy_mapping(id)
proc hasMapping*(id: cint): bool =

View File

@ -14,7 +14,6 @@ import unittest2
import std/atomics
import chronos
import libplum/plum
import libplum/libplum
const miniupnp_protocol {.strdefine.} = ""