From d4ada1b8a392d67f2835935084c5f0f3ecef2ab5 Mon Sep 17 00:00:00 2001 From: Sam T Date: Sat, 29 Jun 2013 23:21:39 +0400 Subject: + Add throughput bench, simplify example. --- examples/Main.hs | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) (limited to 'examples/Main.hs') diff --git a/examples/Main.hs b/examples/Main.hs index fdf982d8..9786dbdc 100644 --- a/examples/Main.hs +++ b/examples/Main.hs @@ -1,13 +1,9 @@ -{-# LANGUAGE ViewPatterns #-} -{-# LANGUAGE PatternGuards #-} module Main (main) where -import Control.Concurrent -import Data.Bitfield +import Control.Monad import Network.BitTorrent import System.Environment -import Control.Monad.Reader -import Data.IORef +import Control.Monad.Trans main :: IO () @@ -20,30 +16,9 @@ main = do client <- newClient 100 [] swarm <- newLeecher client torrent --- storage <- bindStorage swarm "/tmp/" --- discover swarm $ exchange storage + storage <- swarm `bindTo` "/tmp/" - ref <- liftIO $ newIORef 0 discover swarm $ do - forever $ do - e <- awaitEvent - case e of - Available bf - | Just m <- findMin bf -> yieldEvent (Want (BlockIx m 0 10)) - | otherwise -> return () - Want bix -> liftIO $ print bix - Fragment blk -> do - - sc <- liftIO $ getSessionCount swarm - addr <- asks connectedPeerAddr - - liftIO $ do - x <- atomicModifyIORef ref (\x -> (succ x, x)) - if x `mod` 100 == 0 - then print (x, sc, addr) - else return () - - yieldEvent (Want (BlockIx 0 0 (16 * 1024))) - - - print "Bye-bye! =_=" \ No newline at end of file + liftIO $ print "connected to peer" + forever $ exchange storage + liftIO $ print "disconnect to peer" \ No newline at end of file -- cgit v1.2.3