Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified #3472 to make its API more idiomatic.
- Loading branch information
Showing
2 changed files
with
71 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,14 +1,26 @@ | |||
# Stores extra data inside the SSL context. | # Stores extra data inside the SSL context. | ||
import net | import net | ||
|
|
||
let ctx = newContext() | |||
|
|||
# Our unique index for storing foos | # Our unique index for storing foos | ||
let fooIndex = getSslContextExtraDataIndex() | let fooIndex = ctx.getExtraDataIndex() | ||
# And another unique index for storing foos | # And another unique index for storing foos | ||
let barIndex = getSslContextExtraDataIndex() | let barIndex = ctx.getExtraDataIndex() | ||
echo "got indexes ", fooIndex, " ", barIndex | echo "got indexes ", fooIndex, " ", barIndex | ||
|
|
||
let ctx = newContext() | try: | ||
assert ctx.getExtraData(fooIndex) == nil | discard ctx.getExtraData(fooIndex) | ||
let foo: int = 5 | assert false | ||
ctx.setExtraData(fooIndex, cast[pointer](foo)) | except IndexError: | ||
assert cast[int](ctx.getExtraData(fooIndex)) == foo | 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters