From b7faeddf7a6bf2d8ce48f2739d26df528781488f Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Tue, 21 Jul 2015 11:51:33 +0530
Subject: [PATCH] sendMsg: equiv of getMsg but on the sending side

---
 src/FuncTorrent/Peer.hs | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/FuncTorrent/Peer.hs b/src/FuncTorrent/Peer.hs
index f596033..70e89d8 100644
--- a/src/FuncTorrent/Peer.hs
+++ b/src/FuncTorrent/Peer.hs
@@ -8,10 +8,10 @@ import Prelude hiding (lookup, concat, replicate, splitAt, empty, writeFile)
 
 import System.IO (Handle, BufferMode(..), hSetBuffering)
 import Data.ByteString (ByteString, pack, unpack, concat, hGet, hPut, singleton, writeFile)
-import Data.ByteString.Lazy (fromStrict, fromChunks)
+import Data.ByteString.Lazy (fromStrict, fromChunks, toStrict)
 import qualified Data.ByteString.Char8 as BC (replicate, pack, length)
 import Network (connectTo, PortID(..))
-import Data.Binary (Binary(..), decode)
+import Data.Binary (Binary(..), decode, encode)
 import Data.Binary.Put (putWord32be, putWord16be, putWord8)
 import Data.Binary.Get (getWord32be, getWord16be, getWord8, runGet)
 import Control.Monad (replicateM, liftM, forever)
@@ -166,6 +166,11 @@ getMsg h = do
     msg <- hGet h l
     return $ decode $ fromStrict $ concat [lBS, msg]
 
+sendMsg :: Handle -> PeerMsg -> IO ()
+sendMsg h msg =
+  let bsMsg = toStrict $ encode msg
+  in
+   hPut h bsMsg
 
 bsToInt :: ByteString -> Int
 bsToInt x = fromIntegral (runGet getWord32be (fromChunks (return x)))
-- 
2.45.2