summaryrefslogtreecommitdiff
path: root/src/Network/KRPC
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-08 06:48:34 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-08 06:48:34 +0400
commite26ef0001157a1ff6b3a1ec809e5c53c37472161 (patch)
treebdf301031168c21926688fb7612e9bd121b49d71 /src/Network/KRPC
parent6f909c0d81d04b997f8c81ec1ac05e94d7d1e5b6 (diff)
Handle sendmsg failures
Diffstat (limited to 'src/Network/KRPC')
-rw-r--r--src/Network/KRPC/Manager.hs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/Network/KRPC/Manager.hs b/src/Network/KRPC/Manager.hs
index 222b961a..468744c1 100644
--- a/src/Network/KRPC/Manager.hs
+++ b/src/Network/KRPC/Manager.hs
@@ -214,9 +214,11 @@ querySignature name transaction addr = T.concat
214-- we don't need to know about TransactionId while performing query, 214-- we don't need to know about TransactionId while performing query,
215-- so we introduce QueryFailure exceptions 215-- so we introduce QueryFailure exceptions
216 216
217-- | Used to signal 'query' errors.
217data QueryFailure 218data QueryFailure
218 = QueryFailed ErrorCode Text 219 = SendFailed -- ^ unable to send query;
219 | TimeoutExpired 220 | QueryFailed ErrorCode Text -- ^ remote node return error;
221 | TimeoutExpired -- ^ remote node not responding.
220 deriving (Show, Eq, Typeable) 222 deriving (Show, Eq, Typeable)
221 223
222instance Exception QueryFailure 224instance Exception QueryFailure
@@ -253,6 +255,13 @@ queryResponse ares = do
253 Right r -> pure r 255 Right r -> pure r
254 Left e -> throwIO $ QueryFailed ProtocolError (T.pack e) 256 Left e -> throwIO $ QueryFailed ProtocolError (T.pack e)
255 257
258-- (sendmsg EINVAL)
259sendQuery :: BEncode a => Socket -> SockAddr -> a -> IO ()
260sendQuery sock addr q = handle sockError $ sendMessage sock addr q
261 where
262 sockError :: IOError -> IO ()
263 sockError _ = throwIO SendFailed
264
256-- | Enqueue query to the given node. 265-- | Enqueue query to the given node.
257-- 266--
258-- This function should throw 'QueryFailure' exception if quered node 267-- This function should throw 'QueryFailure' exception if quered node
@@ -270,7 +279,7 @@ query addr params = do
270 ares <- registerQuery (tid, addr) pendingCalls 279 ares <- registerQuery (tid, addr) pendingCalls
271 280
272 let q = KQuery (toBEncode params) (methodName queryMethod) tid 281 let q = KQuery (toBEncode params) (methodName queryMethod) tid
273 sendMessage sock addr q 282 sendQuery sock addr q
274 `onException` unregisterQuery (tid, addr) pendingCalls 283 `onException` unregisterQuery (tid, addr) pendingCalls
275 284
276 timeout (optQueryTimeout options * 10 ^ (6 :: Int)) $ do 285 timeout (optQueryTimeout options * 10 ^ (6 :: Int)) $ do