]> git.rkrishnan.org Git - functorrent.git/commitdiff
main: kill FS thread on exit (revisit)
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Fri, 11 Dec 2015 16:48:39 +0000 (22:18 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Fri, 11 Dec 2015 16:48:39 +0000 (22:18 +0530)
src/main/Main.hs

index a7efef0570b878d7be548d1614a045ea4b83ee63..4efd36f37fc2dbe500cb11ca5aa1aa61fd567f97 100644 (file)
@@ -3,7 +3,7 @@ module Main where
 
 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)
@@ -75,7 +75,7 @@ main = do
        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
@@ -90,3 +90,4 @@ main = do
        let p1 = head ps
        handlePeerMsgs p1 peerId m pieceMap True fsMsgChannel
        logStop logR
+       killThread fsTid