From b06b02a0926c34112d96849ec297ecfbd6cd6510 Mon Sep 17 00:00:00 2001 From: Denis Tereshkin Date: Wed, 5 Jan 2022 12:09:20 +0700 Subject: [PATCH] junction: RemoteControl: fix incoming message polling --- src/ATrade/Driver/Junction/RemoteControl.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ATrade/Driver/Junction/RemoteControl.hs b/src/ATrade/Driver/Junction/RemoteControl.hs index f00ecf9..b7e93bb 100644 --- a/src/ATrade/Driver/Junction/RemoteControl.hs +++ b/src/ATrade/Driver/Junction/RemoteControl.hs @@ -98,13 +98,15 @@ handleRemoteControl timeout = do sock <- asks peRemoteControlSocket logger <- asks peLogAction evs <- poll (fromIntegral timeout) [Sock sock [In] Nothing] - unless (null evs) $ do - rawRequest <- liftIO $ receive sock - case parseRemoteControlRequest rawRequest of - Left err -> logErrorWith logger "RemoteControl" ("Unable to parse request: " <> (T.pack . show) err) - Right request -> do - response <- handleRequest request - liftIO $ send sock [] (makeRemoteControlResponse response) + case evs of + (x:_) -> unless (null x) $ do + rawRequest <- liftIO $ receive sock + case parseRemoteControlRequest rawRequest of + Left err -> logErrorWith logger "RemoteControl" ("Unable to parse request: " <> (T.pack . show) err) + Right request -> do + response <- handleRequest request + liftIO $ send sock [] (makeRemoteControlResponse response) + _ -> return () where handleRequest (StartRobot inst) = do startRobot inst