Browse Source

Fix: shutdown on win32

master
Denis Tereshkin 9 years ago
parent
commit
ff0875e989
  1. 3
      src/ATrade/Broker/Server.hs
  2. 4
      src/ATrade/QuoteSource/Client.hs

3
src/ATrade/Broker/Server.hs

@ -66,6 +66,7 @@ startBrokerServer brokers c ep = do @@ -66,6 +66,7 @@ startBrokerServer brokers c ep = do
}
mapM_ (\bro -> setNotificationCallback bro (Just $ notificationCallback state)) brokers
debugM "Broker.Server" "Forking broker server thread"
BrokerServerHandle <$> forkIO (brokerServerThread state) <*> pure compMv
notificationCallback :: IORef BrokerServerState -> Notification -> IO ()
@ -85,6 +86,8 @@ brokerServerThread state = finally brokerServerThread' cleanup @@ -85,6 +86,8 @@ brokerServerThread state = finally brokerServerThread' cleanup
where
brokerServerThread' = forever $ do
sock <- bsSocket <$> readIORef state
evs <- poll 200 [Sock sock [In] Nothing]
when ((L.length . L.head) evs > 0) $ do
msg <- receiveMulti sock
case msg of
[peerId, _, payload] ->

4
src/ATrade/QuoteSource/Client.hs

@ -9,10 +9,12 @@ import ATrade.Types @@ -9,10 +9,12 @@ import ATrade.Types
import Control.Concurrent hiding (readChan, writeChan)
import Control.Concurrent.BoundedChan
import Control.Concurrent.MVar
import Control.Monad
import Control.Exception
import Data.List.NonEmpty
import qualified Data.Text as T
import qualified Data.ByteString.Lazy as BL
import qualified Data.List as L
import Data.Text.Encoding
import System.ZMQ4
import System.Log.Logger
@ -33,6 +35,8 @@ startQuoteSourceClient chan tickers ctx endpoint = do @@ -33,6 +35,8 @@ startQuoteSourceClient chan tickers ctx endpoint = do
return QuoteSourceClientHandle { tid = tid, completionMvar = compMv }
where
clientThread sock = do
evs <- poll 200 [Sock sock [In] Nothing]
when ((L.length . L.head) evs > 0) $ do
rawTick <- fmap BL.fromStrict <$> receiveMulti sock
case deserializeTick rawTick of
Just tick -> writeChan chan tick

Loading…
Cancel
Save