{-# OPTIONS -fglasgow-exts #-} -- Low-level interface/wrappers to FastCGI C client library: -- (). -- This code is based on "Network.FastCGI", and some of it -- is almost identical, but the overall design is new\/simplified. -- Note the rule: the names of all datatypes that are passed to/from -- C functions should start with the letter C: CInt, CDouble, CString. -- Writing fromIntegral is not a chore but necessity, to keep the -- ocde portable. GHC optimizes fromIntegral to NOP if Int is the -- same as CInt. module Network.FastCGI where import Foreign import Foreign.C import Foreign.Storable import Foreign.Marshal import System.Posix ( Fd ) #include -- An environment is an array of strings: type Environ = Ptr CString data FCGX_Request data FCGX_Stream foreign import ccall unsafe "fcgiapp.h FCGX_Init" cFCGX_Init :: IO CInt foreign import ccall unsafe "fcgiapp.h FCGX_OpenSocket" cFCGX_OpenSocket :: CString -> CInt -> IO Fd foreign import ccall unsafe "fcgiapp.h FCGX_InitRequest" cFCGX_InitRequest :: Ptr FCGX_Request -> Fd -> CInt -> IO CInt foreign import ccall unsafe "fcgiapp.h FCGX_Accept_r" cFCGX_Accept_r :: Ptr FCGX_Request -> IO CInt foreign import ccall unsafe "fcgiapp.h FCGX_Finish_r" cFCGX_Finish_r :: Ptr FCGX_Request -> IO () foreign import ccall unsafe "fcgiapp.h FCGX_IsCGI" cFCGX_IsCGI :: IO Bool foreign import ccall unsafe "fcgiapp.h FCGX_GetStr" cFCGX_GetStr :: CString -> CInt -> Ptr FCGX_Stream -> IO CInt foreign import ccall unsafe "fcgiapp.h FCGX_PutStr" cFCGX_PutStr :: CString -> CInt -> Ptr FCGX_Stream -> IO CInt foreign import ccall unsafe "fcgiapp.h FCGX_FFlush" cFCGX_FFlush :: Ptr FCGX_Stream -> IO CInt foreign import ccall unsafe "fcgiapp.h FCGX_SetExitStatus" cFCGX_SetExitStatus :: CInt -> Ptr FCGX_Stream -> IO () -- | Accessors to get the various streams out of the request object. requestIn, requestOut, requestErr :: Ptr FCGX_Request -> IO (Ptr FCGX_Stream) requestIn = #{peek FCGX_Request, in} requestOut = #{peek FCGX_Request, out} requestErr = #{peek FCGX_Request, err} -- | Get the environment out of the request object. requestEnv :: Ptr FCGX_Request -> IO Environ requestEnv = #{peek FCGX_Request, envp} -- Allocate the request object requestSize = #{size FCGX_Request}