|
@@ -3,10 +3,12 @@
|
|
module Walrus.Backend (
|
|
module Walrus.Backend (
|
|
Backend(..),
|
|
Backend(..),
|
|
LazyHandler,
|
|
LazyHandler,
|
|
|
|
+ UIOHandler,
|
|
module Walrus.Backend.Metadata,
|
|
module Walrus.Backend.Metadata,
|
|
parseBackend,
|
|
parseBackend,
|
|
callBackend,
|
|
callBackend,
|
|
- runLazyOnce
|
|
|
|
|
|
+ runLazyOnce,
|
|
|
|
+ runUIOOnce
|
|
) where
|
|
) where
|
|
|
|
|
|
import qualified Data.Attoparsec.ByteString.Char8 as A
|
|
import qualified Data.Attoparsec.ByteString.Char8 as A
|
|
@@ -23,7 +25,7 @@ import Walrus.Backend.Metadata
|
|
import Network
|
|
import Network
|
|
import System.IO
|
|
import System.IO
|
|
import System.IO.Uniform
|
|
import System.IO.Uniform
|
|
-import System.IO.Uniform.Streamline
|
|
|
|
|
|
+import qualified System.IO.Uniform.Streamline as S
|
|
--import System.IO.Uniform.HandlePair as HP
|
|
--import System.IO.Uniform.HandlePair as HP
|
|
--import System.IO.Uniform.Network as Net
|
|
--import System.IO.Uniform.Network as Net
|
|
import qualified System.Process as P
|
|
import qualified System.Process as P
|
|
@@ -32,6 +34,7 @@ data Backend = TCPBackend String Int |
|
|
ExecBackend String [String] deriving (Show, Read, Ord, Eq)
|
|
ExecBackend String [String] deriving (Show, Read, Ord, Eq)
|
|
|
|
|
|
type LazyHandler = Metadata -> LBS.ByteString -> IO (Either String (Metadata, LBS.ByteString))
|
|
type LazyHandler = Metadata -> LBS.ByteString -> IO (Either String (Metadata, LBS.ByteString))
|
|
|
|
+type UIOHandler = Metadata -> S.Streamline IO (Either String (Metadata, LBS.ByteString))
|
|
|
|
|
|
parseBackend :: A.Parser Backend
|
|
parseBackend :: A.Parser Backend
|
|
parseBackend = A.choice [
|
|
parseBackend = A.choice [
|
|
@@ -80,18 +83,32 @@ callBackend b (m, qdt) = do
|
|
repParse = parseMetadata
|
|
repParse = parseMetadata
|
|
|
|
|
|
runLazyOnce :: UniformIO u => u -> LazyHandler -> IO (Either String ())
|
|
runLazyOnce :: UniformIO u => u -> LazyHandler -> IO (Either String ())
|
|
-runLazyOnce u f = withTarget u $ do
|
|
|
|
- m' <- runAttoparsec parseMetadata
|
|
|
|
|
|
+runLazyOnce u f = S.withTarget u $ do
|
|
|
|
+ m' <- S.runAttoparsec parseMetadata
|
|
case m' of
|
|
case m' of
|
|
Left e -> return . Left . show $ e
|
|
Left e -> return . Left . show $ e
|
|
Right m -> do
|
|
Right m -> do
|
|
- dt <- recieveN' $ m^.dataSize
|
|
|
|
|
|
+ dt <- S.recieveN' $ m^.dataSize
|
|
r <- liftIO $ f m dt
|
|
r <- liftIO $ f m dt
|
|
case r of
|
|
case r of
|
|
Left e -> return . Left $ e
|
|
Left e -> return . Left $ e
|
|
Right (mo, dto) -> do
|
|
Right (mo, dto) -> do
|
|
- send $ renderMetadata mo
|
|
|
|
- send' dto
|
|
|
|
|
|
+ S.send $ renderMetadata mo
|
|
|
|
+ S.send' dto
|
|
|
|
+ return . Right $ ()
|
|
|
|
+
|
|
|
|
+runUIOOnce :: UniformIO u => u -> UIOHandler -> IO (Either String ())
|
|
|
|
+runUIOOnce u f = S.withTarget u $ do
|
|
|
|
+ m' <- S.runAttoparsec parseMetadata
|
|
|
|
+ case m' of
|
|
|
|
+ Left e -> return . Left . show $ e
|
|
|
|
+ Right m -> do
|
|
|
|
+ r <- f m
|
|
|
|
+ case r of
|
|
|
|
+ Left e -> return . Left $ e
|
|
|
|
+ Right (mo, dto) -> do
|
|
|
|
+ S.send $ renderMetadata mo
|
|
|
|
+ S.send' dto
|
|
return . Right $ ()
|
|
return . Right $ ()
|
|
|
|
|
|
runTcp :: String -> Int -> LBS.ByteString -> IO LBS.ByteString
|
|
runTcp :: String -> Int -> LBS.ByteString -> IO LBS.ByteString
|