(fastcgi) replace DataRef with a more general Cache type, which can hold several PGF grammars.

This commit is contained in:
bjorn
2008-10-17 14:12:53 +00:00
parent eb0fefec28
commit 0205f341f5
4 changed files with 47 additions and 33 deletions

View File

@@ -2,6 +2,7 @@
import PGF (PGF)
import qualified PGF
import Cache
import FastCGIUtils
import URLEncoding
@@ -17,17 +18,18 @@ import Data.Maybe
import System.Environment
grammarFile :: IO FilePath
grammarFile = do env <- getEnvironment
return $ fromMaybe "grammar.pgf" $ lookup "PGF_FILE" env
defaultGrammarFile :: IO FilePath
defaultGrammarFile =
do env <- getEnvironment
return $ fromMaybe "grammar.pgf" $ lookup "PGF_FILE" env
main :: IO ()
main = do initFastCGI
ref <- grammarFile >>= newDataRef PGF.readPGF
runFastCGIConcurrent' forkIO 100 (handleErrors (handleCGIErrors (fcgiMain ref)))
cache <- newCache PGF.readPGF
runFastCGIConcurrent' forkIO 100 (handleErrors (handleCGIErrors (fcgiMain cache)))
fcgiMain :: DataRef PGF -> CGI CGIResult
fcgiMain ref = liftIO (getData ref) >>= cgiMain
fcgiMain :: Cache PGF -> CGI CGIResult
fcgiMain cache = liftIO (defaultGrammarFile >>= readCache cache) >>= cgiMain
cgiMain :: PGF -> CGI CGIResult
cgiMain pgf =