diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-07 02:33:46 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-07 02:33:46 +0400 |
commit | 2812bdadb55e1ca7a1e5685f3fb2dafe19259970 (patch) | |
tree | b12e146d59d61a9a167720918f110159c5523077 /src/Network/KRPC/Manager.hs | |
parent | 4e1a833637bf613a4674c7c35d4f12c811e9bf7b (diff) |
Ignore EOF exception at recvFrom call
Diffstat (limited to 'src/Network/KRPC/Manager.hs')
-rw-r--r-- | src/Network/KRPC/Manager.hs | 13 |
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 | |||
40 | import Control.Monad.Reader | 40 | import Control.Monad.Reader |
41 | import Control.Monad.Trans.Control | 41 | import Control.Monad.Trans.Control |
42 | import Data.BEncode as BE | 42 | import Data.BEncode as BE |
43 | import Data.ByteString as BS | ||
43 | import Data.ByteString.Char8 as BC | 44 | import Data.ByteString.Char8 as BC |
44 | import Data.ByteString.Lazy as BL | 45 | import Data.ByteString.Lazy as BL |
45 | import Data.IORef | 46 | import Data.IORef |
@@ -53,6 +54,7 @@ import Network.KRPC.Message | |||
53 | import Network.KRPC.Method | 54 | import Network.KRPC.Method |
54 | import Network.Socket hiding (listen) | 55 | import Network.Socket hiding (listen) |
55 | import Network.Socket.ByteString as BS | 56 | import Network.Socket.ByteString as BS |
57 | import System.IO.Error | ||
56 | import System.Timeout | 58 | import System.Timeout |
57 | 59 | ||
58 | 60 | ||
@@ -303,10 +305,17 @@ listener :: MonadKRPC h m => m () | |||
303 | listener = do | 305 | listener = 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. |