From 161ab47b13c214ef4e92962fad1299164bd6fbde Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Thu, 30 Apr 2015 16:59:59 +0530 Subject: [PATCH] wrap network calls with withSocketsDo for multiplatform initialization --- functorrent.cabal | 2 ++ src/FuncTorrent/Network.hs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/functorrent.cabal b/functorrent.cabal index 19a6c92..5e3bf0d 100644 --- a/functorrent.cabal +++ b/functorrent.cabal @@ -37,6 +37,7 @@ library cryptohash, directory, HTTP, + network, network-uri, parsec, QuickCheck, @@ -58,6 +59,7 @@ executable functorrent directory, HTTP, QuickCheck, + network, network-uri, parsec diff --git a/src/FuncTorrent/Network.hs b/src/FuncTorrent/Network.hs index eac69c9..001fe0e 100644 --- a/src/FuncTorrent/Network.hs +++ b/src/FuncTorrent/Network.hs @@ -11,6 +11,7 @@ import Data.ByteString (ByteString) import Data.ByteString.Char8 as BC (pack, unpack, concat, intercalate) import Network.HTTP (simpleHTTP, defaultGETRequest_, getResponseBody) import Network.URI (parseURI) +import Network.Socket (withSocketsDo) -- | Make a query string from a alist of k, v -- TODO: Url encode each argument @@ -18,7 +19,7 @@ mkParams :: [(String, ByteString)] -> ByteString mkParams params = BC.intercalate "&" [concat [pack f, "=", s] | (f,s) <- params] get :: String -> [(String, ByteString)] -> IO ByteString -get url args = simpleHTTP (defaultGETRequest_ url') >>= getResponseBody +get url args = withSocketsDo $ simpleHTTP (defaultGETRequest_ url') >>= getResponseBody where url' = case parseURI $ unpack $ concat [pack url, "?", qstr] of Just x -> x _ -> error "Bad tracker URL" -- 2.37.2