diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-06-12 11:16:21 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-06-12 11:16:21 +0400 |
commit | 4e30588737415d59fa36aa7308c037bb8bd8e3d5 (patch) | |
tree | 110178a60255633036ac4cdb0fdf4367d8aaf907 /exsamples | |
parent | eadb3a6826fb784c33b10b2eab7d4f7bf72b0043 (diff) |
+ Add session exception.
Diffstat (limited to 'exsamples')
-rw-r--r-- | exsamples/Main.hs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/exsamples/Main.hs b/exsamples/Main.hs index a5b865b0..88796642 100644 --- a/exsamples/Main.hs +++ b/exsamples/Main.hs | |||
@@ -6,7 +6,7 @@ import Data.Bitfield | |||
6 | import Network.BitTorrent | 6 | import Network.BitTorrent |
7 | import System.Environment | 7 | import System.Environment |
8 | import Control.Monad.Reader | 8 | import Control.Monad.Reader |
9 | 9 | import Data.IORef | |
10 | 10 | ||
11 | main :: IO () | 11 | main :: IO () |
12 | main = do | 12 | main = do |
@@ -16,6 +16,8 @@ main = do | |||
16 | client <- newClient [] | 16 | client <- newClient [] |
17 | swarm <- newLeacher client torrent | 17 | swarm <- newLeacher client torrent |
18 | 18 | ||
19 | ref <- newIORef 0 | ||
20 | |||
19 | discover swarm $ do | 21 | discover swarm $ do |
20 | addr <- asks connectedPeerAddr | 22 | addr <- asks connectedPeerAddr |
21 | liftIO $ print $ "connected to" ++ show addr | 23 | liftIO $ print $ "connected to" ++ show addr |
@@ -27,7 +29,14 @@ main = do | |||
27 | | Just m <- findMin bf -> yieldEvent (Want (BlockIx m 0 10)) | 29 | | Just m <- findMin bf -> yieldEvent (Want (BlockIx m 0 10)) |
28 | | otherwise -> return () | 30 | | otherwise -> return () |
29 | Want bix -> liftIO $ print bix | 31 | Want bix -> liftIO $ print bix |
30 | Fragment blk -> liftIO $ print (ppBlock blk) | 32 | Fragment blk -> do |
33 | |||
34 | liftIO $ do | ||
35 | readIORef ref >>= print | ||
36 | modifyIORef ref succ | ||
37 | print (ppBlock blk) | ||
38 | |||
39 | yieldEvent (Want (BlockIx 0 0 (16 * 1024))) | ||
31 | 40 | ||
32 | 41 | ||
33 | print "Bye-bye! =_=" \ No newline at end of file | 42 | print "Bye-bye! =_=" \ No newline at end of file |