forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified nim-lang#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 | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
# Stores extra data inside the SSL context. | ||
import net | ||
|
||
let ctx = newContext() | ||
|
||
# Our unique index for storing foos | ||
let fooIndex = getSslContextExtraDataIndex() | ||
let fooIndex = ctx.getExtraDataIndex() | ||
# And another unique index for storing foos | ||
let barIndex = getSslContextExtraDataIndex() | ||
let barIndex = ctx.getExtraDataIndex() | ||
echo "got indexes ", fooIndex, " ", barIndex | ||
|
||
let ctx = newContext() | ||
assert ctx.getExtraData(fooIndex) == nil | ||
let foo: int = 5 | ||
ctx.setExtraData(fooIndex, cast[pointer](foo)) | ||
assert cast[int](ctx.getExtraData(fooIndex)) == foo | ||
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() |
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