-msgLoop pieceStatus file =
- StateT(\pState -> do
- let h = handle pState
- msg <- getMsg h
- liftIO $ putStrLn $ "<-- " ++ show msg ++ "from peer: " ++ show (peer pState)
- case msg of
- KeepAliveMsg -> do
- sendMsg h KeepAliveMsg
- liftIO $ putStrLn $ "--> " ++ "KeepAliveMsg to peer: " ++ show (peer pState)
- runStateT (msgLoop pieceStatus file) pState)
+msgLoop pieceStatus file = do
+ h <- gets handle
+ msg <- liftIO $ getMsg h
+ gets peer >>= (\p -> liftIO $ putStrLn $ "<-- " ++ show msg ++ "from peer: " ++ show p)
+ case msg of
+ KeepAliveMsg -> do
+ liftIO $ sendMsg h KeepAliveMsg
+ gets peer >>= (\p -> liftIO $ putStrLn $ "--> " ++ "KeepAliveMsg to peer: " ++ show p)
+ msgLoop pieceStatus file