mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 17:34:43 +00:00
27 lines
560 B
Nim
27 lines
560 B
Nim
# Stores extra data inside the SSL context.
|
|
import net
|
|
|
|
let ctx = newContext()
|
|
|
|
# Our unique index for storing foos
|
|
let fooIndex = ctx.getExtraDataIndex()
|
|
# And another unique index for storing foos
|
|
let barIndex = ctx.getExtraDataIndex()
|
|
echo "got indexes ", fooIndex, " ", barIndex
|
|
|
|
try:
|
|
discard ctx.getExtraData(fooIndex)
|
|
assert false
|
|
except IndexError:
|
|
echo("Success")
|
|
|
|
type
|
|
FooRef = ref object of RootRef
|
|
foo: int
|
|
|
|
let foo = FooRef(foo: 5)
|
|
ctx.setExtraData(fooIndex, foo)
|
|
doAssert ctx.getExtraData(fooIndex).FooRef == foo
|
|
|
|
ctx.destroyContext()
|