Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

network-conduit

  • Loading branch information...
commit 855b96e3991f7693f77e053d1fac823ecf98e585 1 parent 85b282d
Michael Snoyman authored
1  install-all.sh
View
@@ -11,6 +11,7 @@ pkgs=( conduit
blaze-builder-conduit
filesystem-conduit
zlib-conduit
+ network-conduit
)
# install each sub-respository
37 network-conduit/Data/Conduit/Network.hs
View
@@ -0,0 +1,37 @@
+module Data.Conduit.Network
+ ( sourceSocket
+ , sinkSocket
+ ) where
+
+import Data.Conduit
+import Network.Socket (Socket)
+import Network.Socket.ByteString (sendAll, recv)
+import Data.ByteString (ByteString)
+import qualified Data.ByteString as S
+import Control.Monad.IO.Class (liftIO)
+
+-- | Stream data from the socket.
+--
+-- This function does /not/ automatically close the socket.
+--
+-- Since 0.0.0
+sourceSocket :: ResourceIO m => Socket -> Source m ByteString
+sourceSocket socket = Source $ return $ PreparedSource
+ { sourcePull = do
+ bs <- liftIO (recv socket 4096)
+ return $ if S.null bs then Closed else Open bs
+ , sourceClose = return ()
+ }
+
+-- | Stream data to the socket.
+--
+-- This function does /not/ automatically close the socket.
+--
+-- Since 0.0.0
+sinkSocket :: ResourceIO m => Socket -> Sink ByteString m ()
+sinkSocket socket = Sink $ return $ SinkData
+ { sinkPush = \bs -> do
+ liftIO (sendAll socket bs)
+ return Processing
+ , sinkClose = return ()
+ }
30 network-conduit/LICENSE
View
@@ -0,0 +1,30 @@
+Copyright (c)2011, Michael Snoyman
Felipe Lessa Collaborator

Happy new year! =D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+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 Michael Snoyman 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.
7 network-conduit/Setup.lhs
View
@@ -0,0 +1,7 @@
+#!/usr/bin/env runhaskell
+
+> module Main where
+> import Distribution.Simple
+
+> main :: IO ()
+> main = defaultMain
31 network-conduit/network-conduit.cabal
View
@@ -0,0 +1,31 @@
+Name: network-conduit
+Version: 0.0.0
+Synopsis: Stream socket data using conduits.
+Description: Stream socket data using conduits.
+License: BSD3
+License-file: LICENSE
+Author: Michael Snoyman
+Maintainer: michael@snoyman.com
+Category: Data, Conduit, Network
+Build-type: Simple
+Cabal-version: >=1.8
+Homepage: http://github.com/snoyberg/conduit
+
+flag network-bytestring
+
+Library
+ Exposed-modules: Data.Conduit.Network
+ Build-depends: base >= 4 && < 5
+ , transformers >= 0.2.2 && < 0.3
+ , bytestring >= 0.9
+ , conduit >= 0.0 && < 0.1
+ if flag(network-bytestring)
+ build-depends: network >= 2.2.1 && < 2.2.3
+ , network-bytestring >= 0.1.3 && < 0.1.4
+ else
+ build-depends: network >= 2.3 && < 2.4
+ ghc-options: -Wall
+
+source-repository head
+ type: git
+ location: git://github.com/snoyberg/conduit.git
Felipe Lessa

Happy new year! =D

Please sign in to comment.
Something went wrong with that request. Please try again.