summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Discovery.hs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-13 06:07:52 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-13 06:07:52 +0400
commitbdc0a54c1137a1cb34d0659131a95c64276998da (patch)
treeb24c2de6d8cb29887f27c7ebd642e771939b26ca /src/Network/BitTorrent/Discovery.hs
parenteecd91150b33d6363419daa8e0461984061ed06c (diff)
~ Isolate MVar operations.
Diffstat (limited to 'src/Network/BitTorrent/Discovery.hs')
-rw-r--r--src/Network/BitTorrent/Discovery.hs8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/Network/BitTorrent/Discovery.hs b/src/Network/BitTorrent/Discovery.hs
index 770ae818..1b9e7b26 100644
--- a/src/Network/BitTorrent/Discovery.hs
+++ b/src/Network/BitTorrent/Discovery.hs
@@ -41,16 +41,14 @@ discover swarm @ SwarmSession {..} action = {-# SCC discover #-} do
41 41
42startListener :: ClientSession -> PortNumber -> IO () 42startListener :: ClientSession -> PortNumber -> IO ()
43startListener cs @ ClientSession {..} port = 43startListener cs @ ClientSession {..} port =
44 putMVar peerListener =<< startService port (listener cs (error "listener")) 44 startService peerListener port $ listener cs (error "listener")
45 45
46startDHT :: ClientSession -> PortNumber -> IO () 46startDHT :: ClientSession -> PortNumber -> IO ()
47startDHT ClientSession {..} nodePort = do 47startDHT ClientSession {..} nodePort = withRunning peerListener failure start
48 maybe failure start =<< tryTakeMVar peerListener
49 where 48 where
50 start ClientService {..} = do 49 start ClientService {..} = do
51 ses <- newNodeSession servPort 50 ses <- newNodeSession servPort
52 serv <- startService nodePort (dhtServer ses) 51 startService nodeListener nodePort (dhtServer ses)
53 putMVar nodeListener serv
54 52
55 failure = throwIO $ userError msg 53 failure = throwIO $ userError msg
56 msg = "unable to start DHT server: peer listener is not running" 54 msg = "unable to start DHT server: peer listener is not running"