ngx-export 0.2.5.1 → 0.3.0.0
raw patch · 4 files changed
+60/−20 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ NgxExport: ngxExportAsyncOnReqBody :: Name -> Q [Dec]
Files
- Changelog.md +6/−0
- LICENSE +1/−1
- NgxExport.hs +51/−17
- ngx-export.cabal +2/−2
Changelog.md view
@@ -1,3 +1,9 @@+### 0.3.0.0++- added an asynchronous client request body handler exported with+ *ngxExportAsyncOnReqBody* for using in a new Nginx directive+ *haskell_run_async_on_request_body*.+ ### 0.2.5.1 - added signatures for type-checkers and exporters to prevent warnings when
LICENSE view
@@ -1,7 +1,7 @@ The following license covers this documentation, and the source code, except where otherwise indicated. -Copyright 2016, Alexey Radkov. All rights reserved.+Copyright 2016-2017, 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
@@ -3,7 +3,7 @@ ----------------------------------------------------------------------------- -- | -- Module : NgxExport--- Copyright : (c) Alexey Radkov 2016+-- Copyright : (c) Alexey Radkov 2016-2017 -- License : BSD-style -- -- Maintainer : alexey.radkov@gmail.com@@ -27,6 +27,7 @@ ,ngxExportBY ,ngxExportIOYY ,ngxExportAsyncIOYY+ ,ngxExportAsyncOnReqBody ,ngxExportServiceIOYY ,ngxExportHandler ,ngxExportDefHandler@@ -67,6 +68,7 @@ | YY (B.ByteString -> L.ByteString) | BY (B.ByteString -> Bool) | IOYY (B.ByteString -> Bool -> IO L.ByteString)+ | IOYYY (L.ByteString -> B.ByteString -> IO L.ByteString) | Handler (B.ByteString -> (L.ByteString, String, Int)) | UnsafeHandler (B.ByteString -> (B.ByteString, B.ByteString, Int))@@ -75,7 +77,7 @@ [sigD name [t|NgxExport -> IO CInt|], funD name $ map (\(c, i) -> clause [conP c [wildP]] (normalB [|return i|]) [])- (zip ['SS, 'SSS, 'SLS, 'BS, 'BSS, 'BLS, 'YY, 'BY, 'IOYY,+ (zip ['SS, 'SSS, 'SLS, 'BS, 'BSS, 'BLS, 'YY, 'BY, 'IOYY, 'IOYYY, 'Handler, 'UnsafeHandler] [1 ..] :: [(Name, Int)]) ] @@ -175,6 +177,14 @@ CInt -> CUInt -> Ptr CString -> Ptr CSize -> Ptr CUInt -> IO ()|] -- | Exports a function of type+-- /'L.ByteString' -> 'B.ByteString' -> 'IO' 'L.ByteString'/+-- for using in directive /haskell_run_async_on_request_body/.+ngxExportAsyncOnReqBody =+ ngxExport 'IOYYY 'asyncIOYYY+ [t|Ptr NgxStrType -> CInt -> CString -> CInt ->+ CInt -> Ptr CString -> Ptr CSize -> Ptr CUInt -> IO ()|]++-- | Exports a function of type -- /'B.ByteString' -> 'Bool' -> 'IO' 'L.ByteString'/ -- for using in directive /haskell_run_service/. --@@ -243,6 +253,13 @@ (\(NgxStrType (I m) y) -> peekCStringLen (y, m))) :)) [] [0 .. n - 1] +peekNgxStringArrayLenY :: Ptr NgxStrType -> Int -> IO L.ByteString+peekNgxStringArrayLenY x n = L.fromChunks <$> sequence+ (foldr (\k ->+ ((peekElemOff x k >>=+ (\(NgxStrType (I m) y) ->+ B.unsafePackCStringLen (y, m))) :)) [] [0 .. n - 1])+ pokeCStringLen :: CString -> CSize -> Ptr CString -> Ptr CSize -> IO () pokeCStringLen x n p s = poke p x >> poke s n @@ -252,7 +269,22 @@ poke p t return l -toSingleBuffer :: L.ByteString -> IO (Maybe (CString, Int))+pokeAsyncIOResult :: Ptr CString -> Ptr CSize -> Ptr CUInt ->+ Either String C8L.ByteString -> IO ()+pokeAsyncIOResult p pl r =+ either+ (\s -> do+ PtrLen x l <- newCStringLen s+ pokeCStringLen x l p pl+ poke r 1+ )+ (\s -> do+ PtrLenFromMaybe t l <- toSingleBuffer s+ pokeCStringLen t l p pl+ poke r 0+ )++toSingleBuffer :: L.ByteString -> IO (Maybe CStringLen) toSingleBuffer EmptyLBS = return $ Just (nullPtr, 0) toSingleBuffer s = do@@ -338,20 +370,22 @@ CInt -> CUInt -> Ptr CString -> Ptr CSize -> Ptr CUInt -> IO () asyncIOYY (IOYY f) x (I n) (I fd) ((/= 0) -> fstRun) p pl r = void . async $- (do- s <- (Right <$> (B.unsafePackCStringLen (x, n) >>= flip f fstRun))- `catch` \e -> return $ Left $ show (e :: SomeException)- either- (\s -> do- PtrLen x l <- newCStringLen s- pokeCStringLen x l p pl- poke r 1- )- (\s -> do- PtrLenFromMaybe t l <- toSingleBuffer s- pokeCStringLen t l p pl- poke r 0- ) s+ ((Right <$> (B.unsafePackCStringLen (x, n) >>= flip f fstRun))+ `catch` (\e -> return $ Left $ show (e :: SomeException)) >>=+ pokeAsyncIOResult p pl r+ )+ `finally` ((fdWrite fd "0" >> closeFd fd) `catchIOError` const (return ()))++asyncIOYYY :: NgxExport -> Ptr NgxStrType -> CInt -> CString -> CInt ->+ CInt -> Ptr CString -> Ptr CSize -> Ptr CUInt -> IO ()+asyncIOYYY (IOYYY f) b (I m) x (I n) (I fd) p pl r =+ void . async $+ ((Right <$> do+ b' <- peekNgxStringArrayLenY b m+ x' <- B.unsafePackCStringLen (x, n)+ f b' x'+ ) `catch` (\e -> return $ Left $ show (e :: SomeException)) >>=+ pokeAsyncIOResult p pl r ) `finally` ((fdWrite fd "0" >> closeFd fd) `catchIOError` const (return ()))
ngx-export.cabal view
@@ -1,5 +1,5 @@ name: ngx-export-version: 0.2.5.1+version: 0.3.0.0 synopsis: Helper module for Nginx haskell module description: Helper module for <http://github.com/lyokha/nginx-haskell-module Nginx haskell module>@@ -10,7 +10,7 @@ author: Alexey Radkov <alexey.radkov@gmail.com> maintainer: Alexey Radkov <alexey.radkov@gmail.com> stability: experimental-copyright: 2016 Alexey Radkov+copyright: 2016-2017 Alexey Radkov category: Network build-type: Simple cabal-version: >= 1.8