diff options
Diffstat (limited to 'src/Network/KRPC')
-rw-r--r-- | src/Network/KRPC/Manager.hs | 15 |
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. | ||
217 | data QueryFailure | 218 | data 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 | ||
222 | instance Exception QueryFailure | 224 | instance 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) | ||
259 | sendQuery :: BEncode a => Socket -> SockAddr -> a -> IO () | ||
260 | sendQuery 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 |