Skip to content

Commit 27e4b3a

Browse files
authored
Fix compilation for ARC/ORC (#119)
1 parent 92d350f commit 27e4b3a

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

websock/extensions/compression/deflate.nim

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ const
5353
ExtDeflateThreshold* = 1024
5454
ExtDeflateDecompressLimit* = 10 shl 20 # 10mb
5555

56+
proc destroyExt(ext: DeflateExt) =
57+
if ext.compCtxState != ContextState.Invalid:
58+
# zlib.deflateEnd somehow return DATA_ERROR
59+
# when compression succeed some cases.
60+
# we forget to do something?
61+
discard ext.compCtx.deflateEnd()
62+
ext.compCtxState = ContextState.Invalid
63+
64+
if ext.decompCtxState != ContextState.Invalid:
65+
doAssert(ext.decompCtx.inflateEnd() == Z_OK)
66+
ext.decompCtxState = ContextState.Invalid
67+
68+
# Need to be declared early and not be generic to work with ARC/ORC
69+
proc newDeflateExt: DeflateExt =
70+
result.new(destroyExt)
71+
5672
proc concatParam(resp: var string, param: string) =
5773
resp.add "; "
5874
resp.add param
@@ -327,18 +343,6 @@ method toHttpOptions(ext: DeflateExt): string =
327343
# using paramStr here is a bit clunky
328344
extID & ext.paramStr
329345

330-
proc destroyExt(ext: DeflateExt) =
331-
if ext.compCtxState != ContextState.Invalid:
332-
# zlib.deflateEnd somehow return DATA_ERROR
333-
# when compression succeed some cases.
334-
# we forget to do something?
335-
discard ext.compCtx.deflateEnd()
336-
ext.compCtxState = ContextState.Invalid
337-
338-
if ext.decompCtxState != ContextState.Invalid:
339-
doAssert(ext.decompCtx.inflateEnd() == Z_OK)
340-
ext.decompCtxState = ContextState.Invalid
341-
342346
proc makeOffer(
343347
clientNoContextTakeOver: bool,
344348
clientMaxWindowBits: int): string =
@@ -380,8 +384,7 @@ proc deflateFactory*(
380384
if resp.isErr:
381385
return err(resp.error)
382386

383-
var ext: DeflateExt
384-
ext.new(destroyExt)
387+
var ext = newDeflateExt()
385388
ext.name = extID
386389
ext.paramStr = resp.get()
387390
ext.opts = opts

0 commit comments

Comments
 (0)