import Prelude hiding (log, length, readFile, getContents)
-import Control.Concurrent (forkIO)
+import Control.Concurrent (forkIO, killThread)
import Control.Concurrent.MVar (readMVar)
import Data.ByteString.Char8 (ByteString, getContents, readFile)
import qualified FuncTorrent.FileSystem as FS (createMsgChannel, pieceMapFromFile, startThread)
log $ "Downloading file : " ++ filePath
pieceMap <- FS.pieceMapFromFile filePath fileLen defaultPieceMap
log $ "start filesystem manager thread"
- withFile filePath ReadWriteMode (FS.startThread pieceMap fsMsgChannel)
+ fsTid <- withFile filePath ReadWriteMode (FS.startThread pieceMap fsMsgChannel)
log $ "starting server"
(serverSock, (PortNumber portnum)) <- Server.start
log $ "server started on " ++ show portnum
let p1 = head ps
handlePeerMsgs p1 peerId m pieceMap True fsMsgChannel
logStop logR
+ killThread fsTid