packages feed

connection 0.1.0 → 0.1.1

raw patch · 3 files changed

+26/−23 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Network.Connection: connectionGetChunk' :: Connection -> (ByteString -> (a, ByteString)) -> IO a

Files

Network/Connection.hs view
@@ -28,6 +28,7 @@     -- * Sending and receiving data     , connectionGet     , connectionGetChunk+    , connectionGetChunk'     , connectionPut      -- * TLS related operation@@ -130,25 +131,27 @@ -- however the call will returns as soon as there's data, even if there's less -- data than expected. connectionGet :: Connection -> Int -> IO ByteString-connectionGet con size = withBuffer getData con-    where getData buf-                | B.null buf           = do chunk <- withBackend getMoreData con-                                            let (ret, remain) = B.splitAt size chunk-                                            return (remain, ret)-                | B.length buf >= size = let (ret, remain) = B.splitAt size buf-                                          in return (remain, ret)-                | otherwise            = return (B.empty, buf)-          getMoreData (ConnectionTLS tlsctx) = TLS.recvData tlsctx-          getMoreData (ConnectionStream h)   = hWaitForInput h (-1) >> B.hGetNonBlocking h (16 * 1024)+connectionGet conn size = connectionGetChunk' conn $ B.splitAt size  -- | Get the next block of data from the connection. connectionGetChunk :: Connection -> IO ByteString-connectionGetChunk con = withBuffer getData con-    where getData buf-                | B.null buf = withBackend getMoreData con >>= \chunk -> return (B.empty, chunk)-                | otherwise  = return (B.empty, buf)-          getMoreData (ConnectionTLS tlsctx) = TLS.recvData tlsctx-          getMoreData (ConnectionStream h)   = hWaitForInput h (-1) >> B.hGetNonBlocking h (16 * 1024)+connectionGetChunk conn = connectionGetChunk' conn $ \s -> (s, B.empty)++-- | Like 'connectionGetChunk', but return the unused portion to the buffer,+-- where it will be the next chunk read.+connectionGetChunk' :: Connection -> (ByteString -> (a, ByteString)) -> IO a+connectionGetChunk' conn f = withBuffer getData conn+  where getData buf+          | B.null buf = do+              chunk <- withBackend getMoreData conn+              return $ swap $ f chunk+          | otherwise =+              return $ swap $ f buf++        getMoreData (ConnectionTLS tlsctx) = TLS.recvData tlsctx+        getMoreData (ConnectionStream h)   = B.hGetSome h (16 * 1024)++        swap (a, b) = (b, a)  -- | Close a connection. connectionClose :: Connection -> IO ()
README.md view
@@ -23,7 +23,7 @@         ctx <- initConnectionContext         con <- connectTo ctx $ ConnectionParams                                   { connectionHostname  = "www.example.com"-                                  , connectionPort      = fromIntegral 4567+                                  , connectionPort      = 4567                                   , connectionUseSecure = Nothing                                   , connectionUseSocks  = Nothing                                   }@@ -38,16 +38,16 @@      con <- connectTo ctx $ ConnectionParams                            { connectionHostname  = "www.example.com"-                           , connectionPort      = fromIntegral 4567+                           , connectionPort      = 4567                            , connectionUseSecure = Nothing-                           , connectionUseSocks  = Just $ SockSettingsSimple "localhost" (fromIntegral 1080)+                           , connectionUseSocks  = Just $ SockSettingsSimple "localhost" 1080                            }  Connecting to a SSL style socket is equally easy, and need to set the UseSecure fields in ConnectionParams:      con <- connectTo ctx $ ConnectionParams                            { connectionHostname  = "www.example.com"-                           , connectionPort      = fromIntegral 4567+                           , connectionPort      = 4567                            , connectionUseSecure = Just def                            , connectionUseSocks  = Nothing                            }@@ -65,7 +65,7 @@         ctx <- initConnectionContext         con <- connectTo ctx $ ConnectionParams                                   { connectionHostname  = "www.example.com"-                                  , connectionPort      = fromIntegral 4567+                                  , connectionPort      = 4567                                   , connectionUseSecure = Nothing                                   , connectionUseSocks  = Nothing                                   }
connection.cabal view
@@ -1,9 +1,9 @@ Name:                connection-Version:             0.1.0+Version:             0.1.1 Description:     Simple network library for all your connection need.     .-    Features: Really simple to use, SSL/TLS, SOCKS+    Features: Really simple to use, SSL/TLS, SOCKS.     .     This library provides a very simple api to create sockets     to a destination with the choice of SSL/TLS, and SOCKS.