ngx-export 1.7.9 → 1.7.10
raw patch · 4 files changed
+65/−14 lines, 4 files
Files
- Changelog.md +5/−0
- LICENSE +1/−1
- NgxExport.hs +55/−9
- ngx-export.cabal +4/−4
Changelog.md view
@@ -1,3 +1,8 @@+### 1.7.10++- Added exporter *ngxExportInitHook* which can be used for writing global data+ *synchronously* before the start of handling client requests.+ ### 1.7.9 - Reify types of internal handlers from their signatures.
LICENSE view
@@ -1,7 +1,7 @@ The following license covers this documentation, and the source code, except where otherwise indicated. -Copyright 2016-2023, Alexey Radkov. All rights reserved.+Copyright 2016-2024, Alexey Radkov. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
NgxExport.hs view
@@ -4,7 +4,7 @@ ----------------------------------------------------------------------------- -- | -- Module : NgxExport--- Copyright : (c) Alexey Radkov 2016-2023+-- Copyright : (c) Alexey Radkov 2016-2024 -- License : BSD-style -- -- Maintainer : alexey.radkov@gmail.com@@ -47,6 +47,8 @@ ,ngxExportAsyncHandlerOnReqBody -- *** Service hooks ,ngxExportServiceHook+ -- *** Initialization hook+ ,ngxExportInitHook -- * Accessing Nginx global objects -- *** Opaque pointers ,ngxCyclePtr@@ -223,6 +225,9 @@ type AsyncHandlerRBImpl = Ptr NgxStrType -> Ptr NgxStrType -> CInt -> AsyncHandlerImpl +type InitHookImpl =+ Ptr CString -> Ptr CInt -> IO CUInt+ do TyConI (DataD _ _ _ _ tCs _) <- reify ''NgxExport TyConI (DataD _ _ _ _ aCs _) <- reify ''NgxExportTypeAmbiguityTag@@ -251,6 +256,12 @@ ++ map (\(c, t) -> tySynD (mkName $ nameBase c) [] $ return t) tCons +fExport :: String -> Name -> Type -> Dec+fExport = ((ForeignD .) .) . ExportF CCall++fBody :: Q Exp -> [Q Clause]+fBody b = [clause [] (normalB b) []]+ -- Exporter -> Ambiguity -> Handler impl -> Handler name (Function) -> Decls type NgxExportDec = Name -> Name -> Name -> Name -> Q [Dec] @@ -263,14 +274,14 @@ #endif sequence [sigD nameFt typeFt- ,funD nameFt $ body [|exportType $(conE e `appE` modeF)|]- ,export ftName nameFt <$> typeFt+ ,funD nameFt $ fBody [|exportType $(conE e `appE` modeF)|]+ ,fExport ftName nameFt <$> typeFt ,sigD nameFta typeFta- ,funD nameFta $ body [|exportTypeAmbiguity $(conE a)|]- ,export ftaName nameFta <$> typeFta+ ,funD nameFta $ fBody [|exportTypeAmbiguity $(conE a)|]+ ,fExport ftaName nameFta <$> typeFta ,sigD nameF $ return typeF- ,funD nameF $ body [|$(varE h) $modeF|]- ,return $ export fName nameF typeF+ ,funD nameF $ fBody [|$(varE h) $modeF|]+ ,return $ fExport fName nameF typeF ] where modeF = mode f fName = "ngx_hs_" ++ nameBase f@@ -281,8 +292,6 @@ ftaName = "ambiguity_" ++ fName nameFta = mkName ftaName typeFta = [t|IO CInt|]- body b = [clause [] (normalB b) []]- export = ((ForeignD .) .) . ExportF CCall ngxExport :: NgxExportDec ngxExport = ngxExport' varE@@ -590,6 +599,39 @@ ngxExportServiceHook = ngxExportC 'IOYY 'IOYYSync 'ioyYWithFree +-- | Exports an action of type+--+-- @+-- 'IO' ()+-- @+--+-- as a synchronous initialization hook.+--+-- This can be used to initialize global data /synchronously/ before handling+-- client requests. Note that asynchronous services that write global data on+-- the first run cannot guarantee the data has been written before the start of+-- processing client requests.+--+-- It is not possible to load more than one initialization hook. The hook is+-- only loaded if it has been directly declared in the target library,+-- initialization hooks found in dependent libraries are ignored.+--+-- The hook is not controlled by Nginx directives. If required, data for the+-- initialization hook can be passed in directive /haskell program_options/ and+-- handled with 'System.Environment.getArgs' inside it.+--+-- @since 1.7.10+ngxExportInitHook :: Name -> Q [Dec]+ngxExportInitHook f =+ sequence+ [sigD nameF typeF+ ,funD nameF $ fBody [|initHook $(varE f)|]+ ,fExport fName nameF <$> typeF+ ]+ where fName = "ngx_hsinit_"+ nameF = mkName fName+ typeF = [t|InitHookImpl|]+ data ServiceHookInterrupt = ServiceHookInterrupt instance Exception ServiceHookInterrupt@@ -1031,6 +1073,10 @@ PtrLen t l <- B.unsafeUseAsCStringLen s return pokeCStringLen t l p pl return 0++initHook :: IO () -> InitHookImpl+initHook f p pl =+ safeHandler p pl $ f >> return 0 foreign export ccall ngxExportInstallSignalHandler :: IO () ngxExportInstallSignalHandler :: IO ()
ngx-export.cabal view
@@ -1,8 +1,8 @@ name: ngx-export-version: 1.7.9-synopsis: Helper module for Nginx haskell module+version: 1.7.10+synopsis: Helper module for Nginx Haskell module description: Helper module for- <https://github.com/lyokha/nginx-haskell-module Nginx haskell module>.+ <https://github.com/lyokha/nginx-haskell-module Nginx Haskell module>. homepage: https://github.com/lyokha/nginx-haskell-module license: BSD3 license-file: LICENSE@@ -10,7 +10,7 @@ author: Alexey Radkov <alexey.radkov@gmail.com> maintainer: Alexey Radkov <alexey.radkov@gmail.com> stability: stable-copyright: 2016-2023 Alexey Radkov+copyright: 2016-2024 Alexey Radkov category: Network build-type: Simple cabal-version: 1.20