From: Ramakrishnan Muthukrishnan Date: Fri, 11 Dec 2015 16:48:39 +0000 (+0530) Subject: main: kill FS thread on exit (revisit) X-Git-Url: https://git.rkrishnan.org/frontends/webapi.rst?a=commitdiff_plain;h=8d2bf9f844ac4ea66a1905f55c7f6fb066bf177a;p=functorrent.git main: kill FS thread on exit (revisit) --- diff --git a/src/main/Main.hs b/src/main/Main.hs index a7efef0..4efd36f 100644 --- a/src/main/Main.hs +++ b/src/main/Main.hs @@ -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