module NgxExport.Tools.System (
terminateWorkerProcess
,restartWorkerProcess
,finalizeHTTPRequest
,workerProcessIsExiting
,ngxRequestPtr
,ngxNow
,ngxPid
) where
import NgxExport
import Foreign.Ptr
import Foreign.Storable
import Foreign.C.Types
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as L
import Data.Binary.Get
import Data.Maybe
import Control.Exception
import System.Posix.Types
terminateWorkerProcess :: String -> IO a
terminateWorkerProcess :: forall a. String -> IO a
terminateWorkerProcess = TerminateWorkerProcess -> IO a
forall e a. Exception e => e -> IO a
throwIO (TerminateWorkerProcess -> IO a)
-> (String -> TerminateWorkerProcess) -> String -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> TerminateWorkerProcess
TerminateWorkerProcess
restartWorkerProcess :: String -> IO a
restartWorkerProcess :: forall a. String -> IO a
restartWorkerProcess = RestartWorkerProcess -> IO a
forall e a. Exception e => e -> IO a
throwIO (RestartWorkerProcess -> IO a)
-> (String -> RestartWorkerProcess) -> String -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> RestartWorkerProcess
RestartWorkerProcess
finalizeHTTPRequest :: Int -> Maybe String -> IO a
finalizeHTTPRequest :: forall a. Int -> Maybe String -> IO a
finalizeHTTPRequest = (FinalizeHTTPRequest -> IO a
forall e a. Exception e => e -> IO a
throwIO (FinalizeHTTPRequest -> IO a)
-> (Maybe String -> FinalizeHTTPRequest) -> Maybe String -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((Maybe String -> FinalizeHTTPRequest) -> Maybe String -> IO a)
-> (Int -> Maybe String -> FinalizeHTTPRequest)
-> Int
-> Maybe String
-> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe String -> FinalizeHTTPRequest
FinalizeHTTPRequest
workerProcessIsExiting :: SomeException -> Bool
workerProcessIsExiting :: SomeException -> Bool
workerProcessIsExiting SomeException
e =
Maybe WorkerProcessIsExiting -> Bool
forall a. Maybe a -> Bool
isJust (SomeException -> Maybe WorkerProcessIsExiting
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e :: Maybe WorkerProcessIsExiting)
ngxRequestPtr :: ByteString -> Ptr ()
ngxRequestPtr :: ByteString -> Ptr ()
ngxRequestPtr = WordPtr -> Ptr ()
forall a. WordPtr -> Ptr a
wordPtrToPtr (WordPtr -> Ptr ())
-> (ByteString -> WordPtr) -> ByteString -> Ptr ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> WordPtr
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> WordPtr) -> (ByteString -> Word) -> ByteString -> WordPtr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Get Word -> ByteString -> Word
forall a. Get a -> ByteString -> a
runGet Get Word
getWordhost (ByteString -> Word)
-> (ByteString -> ByteString) -> ByteString -> Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
L.fromStrict
ngxNow :: IO CTime
ngxNow :: IO CTime
ngxNow = IO (Ptr (Ptr ()))
ngxCachedTimePtr IO (Ptr (Ptr ())) -> (Ptr (Ptr ()) -> IO (Ptr ())) -> IO (Ptr ())
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr (Ptr ()) -> IO (Ptr ())
forall a. Storable a => Ptr a -> IO a
peek IO (Ptr ()) -> (Ptr () -> IO CTime) -> IO CTime
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr CTime -> IO CTime
forall a. Storable a => Ptr a -> IO a
peek (Ptr CTime -> IO CTime)
-> (Ptr () -> Ptr CTime) -> Ptr () -> IO CTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr () -> Ptr CTime
forall a b. Ptr a -> Ptr b
castPtr
ngxPid :: IO CPid
ngxPid :: IO CPid
ngxPid = IO CPid
ngxCachedPid