ngx-export 1.1.0 → 1.2.0
raw patch · 3 files changed
+58/−14 lines, 3 files
Files
- Changelog.md +5/−0
- NgxExport.hs +52/−13
- ngx-export.cabal +1/−1
Changelog.md view
@@ -1,3 +1,8 @@+### 1.2.0++- Added exporter *ngxExportServiceHook* for service hooks and exception+ *ServiceHookInterrupt* for interrupting services.+ ### 1.1.0 - Added an asynchronous content handler with direct access to request body
NgxExport.hs view
@@ -38,6 +38,7 @@ ,ngxExportUnsafeHandler ,ngxExportAsyncHandler ,ngxExportAsyncHandlerOnReqBody+ ,ngxExportServiceHook -- * Re-exported data constructors from /"Foreign.C"/ -- (for marshalling in foreign calls) ,Foreign.C.CInt (..)@@ -250,7 +251,7 @@ ngxExportAsyncIOYY :: Name -> Q [Dec] ngxExportAsyncIOYY = ngxExportC 'IOYY 'asyncIOYY- [t|CString -> CInt -> CInt -> CInt -> CUInt -> CUInt ->+ [t|CString -> CInt -> CInt -> CInt -> Ptr CUInt -> CUInt -> CUInt -> Ptr (Ptr NgxStrType) -> Ptr CInt -> Ptr CUInt -> Ptr (StablePtr L.ByteString) -> IO (StablePtr (Async ()))|] @@ -277,7 +278,7 @@ ngxExportServiceIOYY :: Name -> Q [Dec] ngxExportServiceIOYY = ngxExport 'IOYY 'asyncIOYY- [t|CString -> CInt -> CInt -> CInt -> CUInt -> CUInt ->+ [t|CString -> CInt -> CInt -> CInt -> Ptr CUInt -> CUInt -> CUInt -> Ptr (Ptr NgxStrType) -> Ptr CInt -> Ptr CUInt -> Ptr (StablePtr L.ByteString) -> IO (StablePtr (Async ()))|] @@ -336,6 +337,16 @@ Ptr (Ptr NgxStrType) -> Ptr CInt -> Ptr CUInt -> Ptr (StablePtr L.ByteString) -> IO (StablePtr (Async ()))|] +-- | Exports a function of type+-- /'B.ByteString' -> 'IO' 'L.ByteString'/+-- for using in directive /haskell_service_hook/.+ngxExportServiceHook :: Name -> Q [Dec]+ngxExportServiceHook =+ ngxExportC 'IOYY 'ioyYWithFree+ [t|CString -> CInt ->+ Ptr (Ptr NgxStrType) -> Ptr CInt ->+ Ptr (StablePtr L.ByteString) -> IO CUInt|]+ data NgxStrType = NgxStrType CSize CString instance Storable NgxStrType where@@ -351,6 +362,11 @@ poke (castPtr p) n poke (plusPtr p $ alignment x) s +data ServiceHookInterrupt = ServiceHookInterrupt+instance Exception ServiceHookInterrupt+instance Show ServiceHookInterrupt where+ show = const "Service was interrupted by a service hook"+ safeMallocBytes :: Int -> IO (Ptr a) safeMallocBytes = flip catchIOError (const $ return nullPtr) . mallocBytes@@ -502,16 +518,27 @@ pokeLazyByteString s p pl spd return r -ioyY :: IOYY -> CString -> CInt ->+ioyYCommon :: (CStringLen -> IO B.ByteString) ->+ IOYY -> CString -> CInt -> Ptr (Ptr NgxStrType) -> Ptr CInt -> Ptr (StablePtr L.ByteString) -> IO CUInt-ioyY f x (I n) p pl spd = do+ioyYCommon pack f x (I n) p pl spd = do (s, (r, _)) <- safeYYHandler $ do- s <- B.unsafePackCStringLen (x, n) >>= flip f False+ s <- pack (x, n) >>= flip f False fmap (flip (,) (0, False)) $ return $!! s pokeLazyByteString s p pl spd return r +ioyY :: IOYY -> CString -> CInt ->+ Ptr (Ptr NgxStrType) -> Ptr CInt ->+ Ptr (StablePtr L.ByteString) -> IO CUInt+ioyY = ioyYCommon B.unsafePackCStringLen++ioyYWithFree :: IOYY -> CString -> CInt ->+ Ptr (Ptr NgxStrType) -> Ptr CInt ->+ Ptr (StablePtr L.ByteString) -> IO CUInt+ioyYWithFree = ioyYCommon B.unsafePackMallocCStringLen+ asyncIOFlag1b :: B.ByteString asyncIOFlag1b = L.toStrict $ runPut $ putInt8 1 @@ -551,9 +578,10 @@ closeChannel = closeFd fd `catchIOError` const (return ()) asyncIOYY :: IOYY -> CString -> CInt ->- CInt -> CInt -> CUInt -> CUInt -> Ptr (Ptr NgxStrType) -> Ptr CInt ->+ CInt -> CInt -> Ptr CUInt -> CUInt -> CUInt ->+ Ptr (Ptr NgxStrType) -> Ptr CInt -> Ptr CUInt -> Ptr (StablePtr L.ByteString) -> IO (StablePtr (Async ()))-asyncIOYY f x (I n) fd (I fdlk) (ToBool efd) (ToBool fstRun) =+asyncIOYY f x (I n) fd (I fdlk) active (ToBool efd) (ToBool fstRun) = asyncIOCommon (do exiting <- if fstRun && fdlk /= -1@@ -571,6 +599,7 @@ if exiting then return (L.empty, True) else do+ when fstRun $ poke active 1 x' <- B.unsafePackCStringLen (x, n) flip (,) False <$> f x' fstRun ) fd efd@@ -709,14 +738,24 @@ {- SPLICE: END -} -foreign export ccall ngxExportTerminateTask :: StablePtr (Async ()) -> IO ()--ngxExportTerminateTask :: StablePtr (Async ()) -> IO ()-ngxExportTerminateTask = deRefStablePtr >=> cancel+foreign export ccall ngxExportTerminateTask ::+ StablePtr (Async ()) -> IO ()+ngxExportTerminateTask ::+ StablePtr (Async ()) -> IO ()+ngxExportTerminateTask = deRefStablePtr >=>+ cancel -foreign export ccall ngxExportVersion :: Ptr CInt -> CInt -> IO CInt+foreign export ccall ngxExportServiceHookInterrupt ::+ StablePtr (Async ()) -> IO ()+ngxExportServiceHookInterrupt ::+ StablePtr (Async ()) -> IO ()+ngxExportServiceHookInterrupt = deRefStablePtr >=>+ flip throwTo ServiceHookInterrupt . asyncThreadId -ngxExportVersion :: Ptr CInt -> CInt -> IO CInt+foreign export ccall ngxExportVersion ::+ Ptr CInt -> CInt -> IO CInt+ngxExportVersion ::+ Ptr CInt -> CInt -> IO CInt ngxExportVersion x (I n) = fromIntegral <$> foldM (\k (I v) -> pokeElemOff x k v >> return (k + 1)) 0 (take n $ versionBranch version)
ngx-export.cabal view
@@ -1,5 +1,5 @@ name: ngx-export-version: 1.1.0+version: 1.2.0 synopsis: Helper module for Nginx haskell module description: Helper module for <http://github.com/lyokha/nginx-haskell-module Nginx haskell module>