From 61e6254681a1e9e5810a9f2449fadfdc305b1869 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sun, 23 Mar 2014 06:13:56 +0400 Subject: Notify trackers with Stopped event at closeSession --- src/Network/BitTorrent/Client/Handle.hs | 3 ++- src/Network/BitTorrent/Tracker/Session.hs | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Network/BitTorrent/Client/Handle.hs b/src/Network/BitTorrent/Client/Handle.hs index 258af3fb..97ffc637 100644 --- a/src/Network/BitTorrent/Client/Handle.hs +++ b/src/Network/BitTorrent/Client/Handle.hs @@ -110,9 +110,10 @@ openMagnet rootPath uri @ Magnet {..} = do closeHandle :: Handle -> BitTorrent () closeHandle h @ Handle {..} = do freeHandle handleTopic $ do + Client {..} <- getClient stop h liftIO $ Exchange.closeSession handleExchange - liftIO $ Tracker.closeSession handleTrackers + liftIO $ Tracker.closeSession trackerManager handleTrackers {----------------------------------------------------------------------- -- Control diff --git a/src/Network/BitTorrent/Tracker/Session.hs b/src/Network/BitTorrent/Tracker/Session.hs index a17973ad..107b83d6 100644 --- a/src/Network/BitTorrent/Tracker/Session.hs +++ b/src/Network/BitTorrent/Tracker/Session.hs @@ -214,9 +214,12 @@ newSession ih origUris = do , sessionEvents = eventStream } --- | Release scarce resources associated with the given session. -closeSession :: Session -> IO () -closeSession _ = return () +-- | Release scarce resources associated with the given session. This +-- function block until all trackers tied with this peer notified with +-- 'Stopped' event. +closeSession :: Manager -> Session -> IO () +closeSession m s = do + notify m s Stopped {----------------------------------------------------------------------- -- Events @@ -238,8 +241,9 @@ subscribe Session {..} = listen sessionEvents -----------------------------------------------------------------------} -- | Normally you need to use 'Control.Monad.Trans.Resource.alloc'. -withSession :: InfoHash -> TrackerList URI -> (Session -> IO ()) -> IO () -withSession ih uris = bracket (newSession ih uris) closeSession +withSession :: Manager -> InfoHash -> TrackerList URI + -> (Session -> IO ()) -> IO () +withSession m ih uris = bracket (newSession ih uris) (closeSession m) -- | Get last announced status. The only action can alter this status -- is 'notify'. -- cgit v1.2.3