summaryrefslogtreecommitdiff
path: root/src/Network/KRPC/Manager.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-07 02:33:46 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-07 02:33:46 +0400
commit2812bdadb55e1ca7a1e5685f3fb2dafe19259970 (patch)
treeb12e146d59d61a9a167720918f110159c5523077 /src/Network/KRPC/Manager.hs
parent4e1a833637bf613a4674c7c35d4f12c811e9bf7b (diff)
Ignore EOF exception at recvFrom call
Diffstat (limited to 'src/Network/KRPC/Manager.hs')
-rw-r--r--src/Network/KRPC/Manager.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/Network/KRPC/Manager.hs b/src/Network/KRPC/Manager.hs
index ee336a4d..4d1cfb69 100644
--- a/src/Network/KRPC/Manager.hs
+++ b/src/Network/KRPC/Manager.hs
@@ -40,6 +40,7 @@ import Control.Monad.Logger
40import Control.Monad.Reader 40import Control.Monad.Reader
41import Control.Monad.Trans.Control 41import Control.Monad.Trans.Control
42import Data.BEncode as BE 42import Data.BEncode as BE
43import Data.ByteString as BS
43import Data.ByteString.Char8 as BC 44import Data.ByteString.Char8 as BC
44import Data.ByteString.Lazy as BL 45import Data.ByteString.Lazy as BL
45import Data.IORef 46import Data.IORef
@@ -53,6 +54,7 @@ import Network.KRPC.Message
53import Network.KRPC.Method 54import Network.KRPC.Method
54import Network.Socket hiding (listen) 55import Network.Socket hiding (listen)
55import Network.Socket.ByteString as BS 56import Network.Socket.ByteString as BS
57import System.IO.Error
56import System.Timeout 58import System.Timeout
57 59
58 60
@@ -303,10 +305,17 @@ listener :: MonadKRPC h m => m ()
303listener = do 305listener = do
304 Manager {..} <- getManager 306 Manager {..} <- getManager
305 forever $ do 307 forever $ do
306 (bs, addr) <- liftIO $ BS.recvFrom sock maxMsgSize 308 (bs, addr) <- liftIO $ handle exceptions $ BS.recvFrom sock maxMsgSize
307 case BE.decode bs of 309 case BE.decode bs of
308 Left e -> liftIO $ sendMessage sock addr $ unknownMessage e 310 -- TODO ignore unknown messages at all?
311 Left e -> liftIO $ sendMessage sock addr $ unknownMessage e
309 Right m -> handleMessage m addr 312 Right m -> handleMessage m addr
313 where
314 exceptions :: IOError -> IO (BS.ByteString, SockAddr)
315 exceptions e
316 -- packets with empty payload may trigger eof exception
317 | isEOFError e = return ("", SockAddrInet 0 0)
318 | otherwise = throwIO e
310 319
311-- | Should be run before any 'query', otherwise they will never 320-- | Should be run before any 'query', otherwise they will never
312-- succeed. 321-- succeed.