diff options
Diffstat (limited to 'src/Network/KRPC.hs')
-rw-r--r-- | src/Network/KRPC.hs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/Network/KRPC.hs b/src/Network/KRPC.hs index 2c3a1b48..a96d8da9 100644 --- a/src/Network/KRPC.hs +++ b/src/Network/KRPC.hs | |||
@@ -190,7 +190,7 @@ recvResponse sock = do | |||
190 | Right resp -> Right resp | 190 | Right resp -> Right resp |
191 | Left decE -> Left $ case decode raw of | 191 | Left decE -> Left $ case decode raw of |
192 | Right kerror -> kerror | 192 | Right kerror -> kerror |
193 | _ -> ProtocolError (BC.pack decE) | 193 | _ -> KError ProtocolError (BC.pack decE) undefined |
194 | 194 | ||
195 | withRemote :: (MonadBaseControl IO m, MonadIO m) => (Socket -> m a) -> m a | 195 | withRemote :: (MonadBaseControl IO m, MonadIO m) => (Socket -> m a) -> m a |
196 | withRemote = bracket (liftIO (socket AF_INET6 Datagram defaultProtocol)) | 196 | withRemote = bracket (liftIO (socket AF_INET6 Datagram defaultProtocol)) |
@@ -199,8 +199,10 @@ withRemote = bracket (liftIO (socket AF_INET6 Datagram defaultProtocol)) | |||
199 | 199 | ||
200 | getResult :: BEncode result => Socket -> IO result | 200 | getResult :: BEncode result => Socket -> IO result |
201 | getResult sock = do | 201 | getResult sock = do |
202 | resp <- either throw (return . respVals) =<< recvResponse sock | 202 | KResponse {..} <- either throw return =<< recvResponse sock |
203 | either (throw . ProtocolError . BC.pack) return $ fromBEncode resp | 203 | case fromBEncode respVals of |
204 | Left msg -> throw $ KError ProtocolError (BC.pack msg) respId | ||
205 | Right r -> return r | ||
204 | 206 | ||
205 | -- | Makes remote procedure call. Throws RPCException on any error | 207 | -- | Makes remote procedure call. Throws RPCException on any error |
206 | -- occurred. | 208 | -- occurred. |
@@ -233,10 +235,10 @@ handler body = (name, newbody) | |||
233 | {-# INLINE newbody #-} | 235 | {-# INLINE newbody #-} |
234 | newbody addr KQuery {..} = | 236 | newbody addr KQuery {..} = |
235 | case fromBEncode queryArgs of | 237 | case fromBEncode queryArgs of |
236 | Left e -> return (Left (ProtocolError (BC.pack e))) | 238 | Left e -> return $ Left $ KError ProtocolError (BC.pack e) queryId |
237 | Right a -> do | 239 | Right a -> do |
238 | r <- body addr a | 240 | r <- body addr a |
239 | return (Right (KResponse (toBEncode r) queryId)) | 241 | return $ Right $ KResponse (toBEncode r) queryId |
240 | 242 | ||
241 | sockAddrFamily :: SockAddr -> Family | 243 | sockAddrFamily :: SockAddr -> Family |
242 | sockAddrFamily (SockAddrInet _ _ ) = AF_INET | 244 | sockAddrFamily (SockAddrInet _ _ ) = AF_INET |
@@ -265,8 +267,9 @@ remoteServer servAddr action = bracket (liftIO bindServ) (liftIO . sClose) loop | |||
265 | where | 267 | where |
266 | handleMsg bs addr = case decode bs of | 268 | handleMsg bs addr = case decode bs of |
267 | Right query -> (either toBEncode toBEncode <$> action addr query) | 269 | Right query -> (either toBEncode toBEncode <$> action addr query) |
268 | `Lifted.catch` (return . toBEncode . serverError) | 270 | `Lifted.catch` (return . toBEncode . (`serverError` undefined )) |
269 | Left decodeE -> return $ toBEncode (ProtocolError (BC.pack decodeE)) | 271 | Left decodeE -> return $ toBEncode $ |
272 | KError ProtocolError (BC.pack decodeE) undefined | ||
270 | 273 | ||
271 | -- | Run RPC server on specified port by using list of handlers. | 274 | -- | Run RPC server on specified port by using list of handlers. |
272 | -- Server will dispatch procedure specified by callee, but note that | 275 | -- Server will dispatch procedure specified by callee, but note that |
@@ -277,7 +280,7 @@ server :: (MonadBaseControl IO remote, MonadIO remote) | |||
277 | -> [MethodHandler remote] -- ^ Method table. | 280 | -> [MethodHandler remote] -- ^ Method table. |
278 | -> remote () | 281 | -> remote () |
279 | server servAddr handlers = do | 282 | server servAddr handlers = do |
280 | remoteServer servAddr $ \addr q -> do | 283 | remoteServer servAddr $ \addr q @ KQuery {..} -> do |
281 | case L.lookup (queryMethod q) handlers of | 284 | case L.lookup queryMethod handlers of |
282 | Nothing -> return $ Left $ MethodUnknown (queryMethod q) | 285 | Nothing -> return $ Left $ KError MethodUnknown queryMethod queryId |
283 | Just m -> m addr q | 286 | Just m -> m addr q |