]> git.rkrishnan.org Git - functorrent.git/commitdiff
wrap network calls with withSocketsDo for multiplatform initialization
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Thu, 30 Apr 2015 11:29:59 +0000 (16:59 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Thu, 30 Apr 2015 11:30:43 +0000 (17:00 +0530)
functorrent.cabal
src/FuncTorrent/Network.hs

index 19a6c92084caedd61102f674ecc933f536a2209d..5e3bf0d959616a3381e3a5beb95ed9bc2a2eec45 100644 (file)
@@ -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
 
index eac69c9e32357f42023e0c6f702081039fb32c85..001fe0ee90c34308fb1afb8f5ea86becd171f1ac 100644 (file)
@@ -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"