Permalink
Browse files

Remove everything except pipes-extra.

  • Loading branch information...
1 parent 2caecb4 commit e37048a981e879afd04fc50baa8c45d7cc68f2a3 @pcapriotti committed Apr 9, 2012
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -1,10 +1,3 @@
Collection of basic utilities for [pipes][1].
- * **pipes-attoparsec**: Utilities to convert a parser into a pipe.
- * **pipes-extra**: File readers and writers, chunk pipes.
- * **pipes-conduit**: [Conduit][2] adapters.
- * **pipes-network**: Utilities to deal with sockets. Ported from conduit.
- * **pipes-zlib**: Pipes to deal with zipped data. Ported from conduit.
-
- [1]: https://github.com/pcapriotti/Haskell-Pipes-Library
- [2]: http://hackage.haskell.org/package/conduit
+ [1]: https://github.com/pcapriotti/pipes-core
File renamed without changes.
@@ -1,45 +0,0 @@
-{-# LANGUAGE DeriveDataTypeable #-}
-module Control.Pipe.Attoparsec (
- ParseError(..),
- pipeParser,
- ) where
-
-import qualified Control.Exception as E
-import Control.Pipe
-import Control.Pipe.Combinators
-import Control.Pipe.Exception
-import Data.Attoparsec.Types
-import Data.Maybe
-import Data.Monoid
-import Data.Typeable
-
--- | A parse error as returned by Attoparsec.
-data ParseError
- = ParseError {
- errorContexts :: [String], -- ^ Contexts where the error occurred.
- errorMessage :: String -- ^ Error message.
- }
- | DivergentParser -- ^ Returned if a parser does not terminate
- -- when its input is exhausted.
- deriving (Show, Typeable)
-
-instance E.Exception ParseError
-
--- | Convert a parser continuation into a Pipe.
---
--- To get a parser continuation from a 'Parser', use the @parse@ function of the
--- appropriate Attoparsec module.
-pipeParser :: (Monoid a, Monad m) => (a -> IResult a r) -> Pipe a x m (a, Either ParseError r)
-pipeParser p = go p
- where
- go p = do
- chunk <- tryAwait
- case p (maybe mempty id chunk) of
- Fail leftover contexts msg ->
- return (leftover, Left $ ParseError contexts msg)
- Partial p' ->
- if isNothing chunk
- then return (mempty, Left DivergentParser)
- else go p'
- Done leftover result ->
- return (leftover, Right result)
@@ -1,24 +0,0 @@
-Name: pipes-attoparsec
-Version: 0.0.2
-License: BSD3
-License-file: LICENSE
-Author: Paolo Capriotti
-Maintainer: p.capriotti@gmail.com
-Stability: Experimental
-Homepage: https://github.com/pcapriotti/pipes-extra
-Category: Text
-Build-type: Simple
-Synopsis: Utilities to convert a parser into a pipe.
-Description: Utilities to convert a parser into a pipe.
-Cabal-version: >=1.8
-
-Source-Repository head
- Type: git
- Location: https://github.com/pcapriotti/pipes-extra
-
-Library
- Exposed-modules: Control.Pipe.Attoparsec
- Build-depends:
- base (== 4.*),
- pipes-core (== 0.1.*),
- attoparsec (== 0.10.*)
@@ -1,73 +0,0 @@
--- | Adapters to convert conduits to pipes.
-module Control.Pipe.Conduit (
- -- ** Sources
- sourcePipe,
- -- ** Conduits
- conduitPipe,
- conduitPipe_,
- -- ** Sinks
- sinkPipe,
- sinkPipe_
- ) where
-
-import Control.Monad (void)
-import Control.Monad.Trans.Class
-import Control.Monad.Trans.Resource
-import Control.Pipe
-import Control.Pipe.Combinators
-import Control.Pipe.Exception
-import Data.Conduit
-
--- | Convert a 'Conduit' to 'Pipe'.
---
--- The resulting pipe behaves like the original 'Conduit', and closes it upon
--- termination. Any unconsumed input is returned.
-conduitPipe :: Resource m => Conduit a m b -> Pipe a b (ResourceT m) (Maybe a)
-conduitPipe (Conduit push close) = do
- x <- tryAwait
- case x of
- Nothing -> lift close >>= mapM_ yield >> return Nothing
- Just input -> do
- result <- lift $ push input
- case result of
- Producing c' output -> mapM_ yield output >> conduitPipe c'
- Finished input' output -> mapM_ yield output >> return input'
-
--- | Convert a 'Conduit' to a 'Pipe', ignoring unconsumed input.
-conduitPipe_ :: Resource m => Conduit a m b -> Pipe a b (ResourceT m) ()
-conduitPipe_ = void . conduitPipe
-
--- | Convert a 'Source' into a 'Pipe'.
---
--- The resulting 'Pipe' is a 'Producer' which pulls from the 'Source' until
--- exhaustion and yields the received data.
-sourcePipe :: Resource m => Source m a -> Pipe x a (ResourceT m) ()
-sourcePipe (Source pull _) = do
- result <- lift pull
- case result of
- Open s x -> yield x >> sourcePipe s
- Closed -> return ()
-
--- | Convert a 'Sink' into a 'Pipe'.
---
--- Optional consumed input is returned, together with the sink result.
-sinkPipe :: Resource m => Sink a m b -> Pipe a x (ResourceT m) (Maybe a, b)
-sinkPipe (SinkNoData out) = return (Nothing, out)
-sinkPipe (SinkLift m) = lift m >>= sinkPipe
-sinkPipe (SinkData p c) = go p c
- where
- go push close = do
- mx <- tryAwait
- case mx of
- Nothing -> do
- out <- lift close
- return (Nothing, out)
- Just x -> do
- result <- lift $ push x
- case result of
- Processing push' close' -> go push' close'
- Done input output -> return (input, output)
-
--- | Convert a 'Sink' into a 'Pipe', ignoring results.
-sinkPipe_ :: Resource m => Sink a m b -> Pipe a x (ResourceT m) ()
-sinkPipe_ = void . sinkPipe
View
@@ -1,30 +0,0 @@
-Copyright (c)2012, Paolo Capriotti
-
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of Paolo Capriotti nor the names of other
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -1,2 +0,0 @@
-import Distribution.Simple
-main = defaultMain
@@ -1,25 +0,0 @@
-Name: pipes-conduit
-Version: 0.0.2
-License: BSD3
-License-file: LICENSE
-Author: Paolo Capriotti
-Maintainer: p.capriotti@gmail.com
-Stability: Experimental
-Homepage: https://github.com/pcapriotti/pipes-extra
-Category: Control, Enumerator
-Build-type: Simple
-Synopsis: Conduit adapters
-Description: Conduit adapters
-Cabal-version: >=1.8
-
-Source-Repository head
- Type: git
- Location: https://github.com/pcapriotti/pipes-extra
-
-Library
- Exposed-modules: Control.Pipe.Conduit
- Build-depends:
- base (== 4.*),
- transformers (== 0.2.*),
- pipes-core (== 0.1.*),
- conduit (== 0.2.*)
File renamed without changes.
View
@@ -1,30 +0,0 @@
-Copyright (c)2012, Paolo Capriotti
-
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
-
- * Neither the name of Paolo Capriotti nor the names of other
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -1,2 +0,0 @@
-import Distribution.Simple
-main = defaultMain
@@ -1,130 +0,0 @@
-{-# LANGUAGE ScopedTypeVariables #-}
-module Control.Pipe.Network (
- Application,
- socketReader,
- socketWriter,
- ServerSettings(..),
- runTCPServer,
- ClientSettings(..),
- runTCPClient,
- ) where
-
-import qualified Network.Socket as NS
-import Network.Socket (Socket)
-import Network.Socket.ByteString (sendAll, recv)
-import Data.ByteString (ByteString)
-import qualified Data.ByteString as B
-import Control.Concurrent (forkIO)
-import qualified Control.Exception as E
-import Control.Monad (forever, unless)
-import Control.Monad.IO.Class
-import Control.Monad.Trans.Class
-import Control.Pipe
-
--- adapted from conduit
-
--- | Stream data from the socket.
-socketReader :: MonadIO m => Socket -> Pipe () ByteString m ()
-socketReader socket = go
- where
- go = do
- bs <- lift . liftIO $ recv socket 4096
- unless (B.null bs) $
- yield bs >> go
-
--- | Stream data to the socket.
-socketWriter :: MonadIO m => Socket -> Pipe ByteString Void m r
-socketWriter socket = forever $ await >>= lift . liftIO . sendAll socket
-
--- | A simple TCP application. It takes two arguments: the 'Producer' to read
--- input data from, and the 'Consumer' to send output data to.
-type Application m r = Pipe () ByteString m ()
- -> Pipe ByteString Void m ()
- -> IO r
-
--- | Settings for a TCP server. It takes a port to listen on, and an optional
--- hostname to bind to.
-data ServerSettings = ServerSettings
- { serverPort :: Int
- , serverHost :: Maybe String -- ^ 'Nothing' indicates no preference
- }
-
--- | Run an @Application@ with the given settings. This function will create a
--- new listening socket, accept connections on it, and spawn a new thread for
--- each connection.
-runTCPServer :: MonadIO m => ServerSettings -> Application m r -> IO r
-runTCPServer (ServerSettings port host) app = E.bracket
- (bindPort host port)
- NS.sClose
- (forever . serve)
- where
- serve lsocket = do
- (socket, _addr) <- NS.accept lsocket
- forkIO $ do
- E.finally
- (app (socketReader socket) (socketWriter socket))
- (NS.sClose socket)
- return ()
-
--- | Settings for a TCP client, specifying how to connect to the server.
-data ClientSettings = ClientSettings
- { clientPort :: Int
- , clientHost :: String
- }
-
--- | Run an 'Application' by connecting to the specified server.
-runTCPClient :: MonadIO m => ClientSettings -> Application m r -> IO r
-runTCPClient (ClientSettings port host) app = E.bracket
- (getSocket host port)
- NS.sClose
- (\s -> app (socketReader s) (socketWriter s))
-
--- | Attempt to connect to the given host/port.
-getSocket :: String -> Int -> IO NS.Socket
-getSocket host' port' = do
- let hints = NS.defaultHints {
- NS.addrFlags = [NS.AI_ADDRCONFIG]
- , NS.addrSocketType = NS.Stream
- }
- (addr:_) <- NS.getAddrInfo (Just hints) (Just host') (Just $ show port')
- E.bracketOnError
- (NS.socket (NS.addrFamily addr)
- (NS.addrSocketType addr)
- (NS.addrProtocol addr))
- NS.sClose
- (\sock -> NS.connect sock (NS.addrAddress addr) >> return sock)
-
--- | Attempt to bind a listening @Socket@ on the given host/port. If no host is
--- given, will use the first address available.
-bindPort :: Maybe String -> Int -> IO Socket
-bindPort host p = do
- let hints = NS.defaultHints
- { NS.addrFlags =
- [ NS.AI_PASSIVE
- , NS.AI_NUMERICSERV
- , NS.AI_NUMERICHOST
- ]
- , NS.addrSocketType = NS.Stream
- }
- port = Just . show $ p
- addrs <- NS.getAddrInfo (Just hints) host port
- let
- tryAddrs (addr1:rest@(_:_)) = E.catch
- (theBody addr1)
- (\(_ :: E.IOException) -> tryAddrs rest)
- tryAddrs (addr1:[]) = theBody addr1
- tryAddrs _ = error "bindPort: addrs is empty"
- theBody addr =
- E.bracketOnError
- (NS.socket
- (NS.addrFamily addr)
- (NS.addrSocketType addr)
- (NS.addrProtocol addr))
- NS.sClose
- (\sock -> do
- NS.setSocketOption sock NS.ReuseAddr 1
- NS.bindSocket sock (NS.addrAddress addr)
- NS.listen sock NS.maxListenQueue
- return sock
- )
- tryAddrs addrs
Oops, something went wrong.

0 comments on commit e37048a

Please sign in to comment.