Skip to content

Commit

Permalink
Fix compiler warnings
Browse files Browse the repository at this point in the history
Now compiler warning free with ghc versions 7.6.3, 7.8.3, 7.10.3
and 8.0.1.
  • Loading branch information
erikd committed Jan 6, 2017
1 parent 32afbec commit 7d628d1
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 40 deletions.
9 changes: 9 additions & 0 deletions src/AdaptGhcVersion.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{-# LANGUAGE CPP #-}
module AdaptGhcVersion
(
Monoid (..), (<$>), (<*>), pure
) where

import Control.Applicative ((<$>), (<*>), pure)
import Data.Monoid (Monoid (..))

2 changes: 0 additions & 2 deletions src/Digest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ module Digest
)
where

import Control.DeepSeq

import qualified Data.ByteString as B

import qualified Data.ByteString.Lazy as L
Expand Down
2 changes: 1 addition & 1 deletion src/Process.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Control.Monad.State.Strict

import Data.Typeable

import Prelude hiding (catch, log)
import Prelude hiding (log)

import System.Log.Logger

Expand Down
4 changes: 2 additions & 2 deletions src/Process/ChokeMgr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import qualified Data.Set as S
import Data.Traversable as T
import GHC.Generics

import Prelude hiding (catch, log)
import Prelude hiding (log)

import System.Random

Expand Down Expand Up @@ -246,7 +246,7 @@ compareInv x y =
EQ -> EQ
GT -> LT

comparingWith :: Ord a => (a -> a -> Ordering) -> (b -> a) -> b -> b -> Ordering
comparingWith :: (a -> a -> Ordering) -> (b -> a) -> b -> b -> Ordering
comparingWith comp project x y =
comp (project x) (project y)

Expand Down
2 changes: 1 addition & 1 deletion src/Process/Console.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Control.Concurrent
import Control.Concurrent.STM
import Control.Monad.Reader

import Prelude hiding (catch)
import Prelude


import Process
Expand Down
6 changes: 3 additions & 3 deletions src/Process/Listen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Control.Monad.Reader

import Data.Word

import Network hiding (accept, sClose)
import Network hiding (accept)
import Network.Socket
import Network.BSD

Expand All @@ -33,10 +33,10 @@ openListen port = liftIO $ do
proto <- getProtocolNumber "tcp"
bracketOnError
(socket AF_INET Stream proto)
(sClose)
(close)
(\sock -> do
setSocketOption sock ReuseAddr 1
bindSocket sock (SockAddrInet (toEnum $ fromIntegral port) iNADDR_ANY)
bind sock (SockAddrInet (toEnum $ fromIntegral port) iNADDR_ANY)
listen sock maxListenQueue
return sock
)
Expand Down
11 changes: 6 additions & 5 deletions src/Process/Peer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module Process.Peer (
)
where

import Control.Applicative
import AdaptGhcVersion

import Control.Concurrent
import Control.Concurrent.STM
import Control.DeepSeq
Expand All @@ -18,7 +19,7 @@ import Control.Exception
import Control.Monad.State
import Control.Monad.Reader

import Prelude hiding (catch, log)
import Prelude hiding (log)

import Data.Array
import Data.Bits
Expand All @@ -27,7 +28,7 @@ import Data.Function (on)

import qualified Data.PieceSet as PS
import Data.Maybe
import Data.Monoid(Monoid(..), Last(..))
import Data.Monoid(Last(..))

import Data.Set as S hiding (map, foldl)
import Data.Time.Clock
Expand Down Expand Up @@ -790,8 +791,8 @@ allowedFast ip ihash sz n = generate n [] x []
bytes :: [Word32]
bytes = [fromIntegral z `shiftL` s |
(z, s) <- zip (B.unpack h) [24,16,8,0]]
ntohl = fromIntegral . sum
in ((ntohl bytes) `mod` fromIntegral sz) : genPieces rest
fntohl = fromIntegral . sum
in ((fntohl bytes) `mod` fromIntegral sz) : genPieces rest
-- To prevent a Peer to reconnect, obtain a new IP and thus new FAST-set pieces, we mask out
-- the lower bits
ipBytes = B.pack $ map fromIntegral
Expand Down
2 changes: 1 addition & 1 deletion src/Process/Peer/Receiver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Control.Monad.Reader
import Control.Monad.State

import qualified Data.ByteString as B
import Prelude hiding (catch, log)
import Prelude hiding (log)

import Data.Serialize.Get

Expand Down
2 changes: 1 addition & 1 deletion src/Process/Peer/Sender.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ start :: Socket -> TMVar L.ByteString -> SupervisorChannel -> IO ThreadId
start s ch supC = spawnP (CF ch s) () ({-# SCC "Sender" #-}
(cleanupP pgm
(defaultStopHandler supC)
(liftIO $ sClose s)))
(liftIO $ close s)))
pgm :: Process CF () ()
pgm = do
ch <- asks chan
Expand Down
2 changes: 1 addition & 1 deletion src/Process/Peer/SenderQ.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Control.Concurrent.STM
import Control.Monad.Reader
import Control.Monad.State

import Prelude hiding (catch, log)
import Prelude hiding (log)

import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
Expand Down
8 changes: 5 additions & 3 deletions src/Process/PeerMgr.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE CPP, TupleSections #-}
module Process.PeerMgr (
-- * Types
Peer(..)
Expand All @@ -10,7 +10,9 @@ module Process.PeerMgr (
)
where

import Control.Applicative
#if __GLASGOW_HASKELL__ <= 708
import AdaptGhcVersion
#endif

import Control.Concurrent
import Control.Concurrent.STM
Expand Down Expand Up @@ -112,7 +114,7 @@ incomingPeers msg =
_ <- addIncoming conn
return ()
else do debugP "Already too many peers, closing!"
liftIO $ Sock.sClose s
liftIO $ Sock.close s
NewTorrent ih tl -> do
modify (\s -> s { cmMap = M.insert ih tl (cmMap s)})
StopTorrent _ih -> do
Expand Down
35 changes: 19 additions & 16 deletions src/Process/Tracker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
-- about the torrent in question. It may also respond with an error in which
-- case we should present it to the user.
--
{-# LANGUAGE CPP #-}
module Process.Tracker
( start
)
where

import Prelude hiding (catch)
import Control.Applicative
#if __GLASGOW_HASKELL__ <= 708
import AdaptGhcVersion
#endif

import Control.Concurrent
import Control.Concurrent.STM
import Control.Monad.Reader
Expand Down Expand Up @@ -206,7 +209,7 @@ decodeIps4 bs | B.null bs = []
let (ip, r1) = B.splitAt 4 bs
(port, r2) = B.splitAt 2 r1
i' = cW32 ip
p' = PortNum $ cW16 port
p' = fromIntegral $ cW16 port
in PeerMgr.Peer (S.SockAddrInet p' i') : decodeIps4 r2
| otherwise = [] -- Some trackers fail spectacularly

Expand All @@ -216,7 +219,7 @@ decodeIps6 bs | B.null bs = []
let (ip6, r1) = B.splitAt 16 bs
(port, r2) = B.splitAt 2 r1
i' = cW128 ip6
p' = PortNum $ cW16 port
p' = fromIntegral $ cW16 port
in PeerMgr.Peer (S.SockAddrInet6 p' 0 i' 0) : decodeIps6 r2
| otherwise = [] -- Some trackers fail spectacularly

Expand All @@ -241,12 +244,12 @@ cW128 bs =
bubbleUpURL :: AnnounceURL -> [AnnounceURL] -> Process CF ST ()
bubbleUpURL _ (_:[]) = return ()
bubbleUpURL _ [] = return ()
bubbleUpURL url tier@(x:_) = if url == x
bubbleUpURL url tier@(x:_) = if url == x
then return ()
else do
alist <- gets announceList
let newTier = url : filter (/=url) tier
newAnnounceList = map (\a -> if a /= tier then a else newTier) alist
let newTier = url : filter (/=url) tier
newAnnounceList = map (\a -> if a /= tier then a else newTier) alist
_ <- modify (\s -> s { announceList = newAnnounceList })
return ()

Expand All @@ -258,9 +261,9 @@ tryThisTier' s (x:xs) = do url <- buildRequestURL s x
Just u -> return u
resp <- trackerRequest uri
case resp of
Left m -> if null xs
Left m -> if null xs
then return $ Left m
else tryThisTier' s xs
else tryThisTier' s xs
Right r -> return $ Right (x, r)


Expand All @@ -277,22 +280,22 @@ tryThisTier params tier = do resp <- tryThisTier' params tier

queryTrackers' :: Status.StatusState -> [[AnnounceURL]] -> Process CF ST (Either String TrackerResponse)
queryTrackers' _ [] = return $ Left "Empty announce-list"
queryTrackers' p (x:[]) = tryThisTier p x --last element, so return whatever it gives us
queryTrackers' p (x:[]) = tryThisTier p x --last element, so return whatever it gives us
queryTrackers' p (x:xs) = do resp <- tryThisTier p x
case resp of
Left _ -> queryTrackers' p xs -- in case of error, move to the next tier
case resp of
Left _ -> queryTrackers' p xs -- in case of error, move to the next tier
Right _ -> return $ resp -- if success just return result

queryTrackers :: Status.StatusState -> Process CF ST (Either String TrackerResponse)
queryTrackers ss = do alist <- gets announceList
queryTrackers ss = do alist <- gets announceList
queryTrackers' ss alist



-- TODO: Do not recurse infinitely here.
trackerRequest :: URI -> Process CF ST (Either String TrackerResponse)
trackerRequest uri =
do debugP $ "Querying URI: " ++ (show uri)
do debugP $ "Querying URI: " ++ (show uri)
resp <- liftIO $ catch (simpleHTTP request) (\e -> let err = show (e :: IOException)
in return . Left . ErrorMisc $ err)
case resp of
Expand Down Expand Up @@ -341,7 +344,7 @@ urlEncode (h:t) = let str = if reserved (ord h) then escape h else [h]
| x >= ord 'A' && x <= ord 'Z' = False
| x >= ord '0' && x <= ord '9' = False
| x <= 0x20 || x >= 0x7F = True
| otherwise = x `elem` map ord
| otherwise = x `elem` map ord
[';','/','?',':','@','&'
,'=','+',',','$','{','}'
,'|','\\','^','[',']','`'
Expand Down
2 changes: 1 addition & 1 deletion src/Protocol/Wire.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Control.Monad
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L

import Data.Attoparsec as A
import Data.Attoparsec.ByteString as A
import Data.Bits (testBit, setBit)

import Data.Serialize
Expand Down
2 changes: 1 addition & 1 deletion src/Supervisor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Control.Concurrent.STM
import Control.Monad.State
import Control.Monad.Reader

import Prelude hiding (catch)
import Prelude

import Process

Expand Down
7 changes: 5 additions & 2 deletions src/Torrent.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE DeriveGeneric, FlexibleContexts #-}
{-# LANGUAGE CPP, DeriveGeneric, FlexibleContexts #-}

-- | The following module is responsible for general types used
-- throughout the system.
Expand Down Expand Up @@ -27,7 +27,10 @@ module Torrent (
)
where

import Control.Applicative
#if __GLASGOW_HASKELL__ <= 708
import AdaptGhcVersion
#endif

import Control.DeepSeq

import Data.Array
Expand Down

0 comments on commit 7d628d1

Please sign in to comment.