Browse Source

setLinger 0 on all sockets

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

1
src/ATrade/Broker/Client.hs

@ -55,6 +55,7 @@ brokerClientThread ctx ep cmd resp comp killMv secParams = finally brokerClientT
throwIO e throwIO e
else do else do
putMVar resp (ResponseError "Response error")) $ withSocket ctx Req (\sock -> do putMVar resp (ResponseError "Response error")) $ withSocket ctx Req (\sock -> do
setLinger (restrict 0) sock
debugM "Broker.Client" $ "Connecting to: " ++ show (T.unpack ep) debugM "Broker.Client" $ "Connecting to: " ++ show (T.unpack ep)
case cspCertificate secParams of case cspCertificate secParams of
Just clientCert -> zapApplyCertificate clientCert sock Just clientCert -> zapApplyCertificate clientCert sock

2
src/ATrade/Broker/Server.hs

@ -58,6 +58,7 @@ data BrokerServerHandle = BrokerServerHandle ThreadId ThreadId (MVar ()) (MVar (
startBrokerServer :: [BrokerInterface] -> Context -> T.Text -> T.Text -> ServerSecurityParams -> IO BrokerServerHandle startBrokerServer :: [BrokerInterface] -> Context -> T.Text -> T.Text -> ServerSecurityParams -> IO BrokerServerHandle
startBrokerServer brokers c ep tradeSinkEp params = do startBrokerServer brokers c ep tradeSinkEp params = do
sock <- socket c Router sock <- socket c Router
setLinger (restrict 0) sock
case sspDomain params of case sspDomain params of
Just domain -> setZapDomain domain sock Just domain -> setZapDomain domain sock
Nothing -> return () Nothing -> return ()
@ -109,6 +110,7 @@ tradeSinkHandler :: Context -> IORef BrokerServerState -> T.Text -> IO ()
tradeSinkHandler c state tradeSinkEp = when (tradeSinkEp /= "") $ tradeSinkHandler c state tradeSinkEp = when (tradeSinkEp /= "") $
whileM_ (not <$> wasKilled) $ whileM_ (not <$> wasKilled) $
withSocket c Dealer (\sock -> do withSocket c Dealer (\sock -> do
setLinger (restrict 0) sock
chan <- tradeSink <$> readIORef state chan <- tradeSink <$> readIORef state
connect sock $ T.unpack tradeSinkEp connect sock $ T.unpack tradeSinkEp
timeoutMv <- newEmptyMVar timeoutMv <- newEmptyMVar

1
src/ATrade/QuoteSource/Client.hs

@ -51,6 +51,7 @@ startQuoteSourceClient chan tickers ctx endpoint = do
return QuoteSourceClientHandle { tid = tid, completionMvar = compMv, killMVar = killMv } return QuoteSourceClientHandle { tid = tid, completionMvar = compMv, killMVar = killMv }
where where
clientThread lastHeartbeat killMv = whileM_ (isNothing <$> tryReadMVar killMv) $ withSocket ctx Sub (\sock -> do clientThread lastHeartbeat killMv = whileM_ (isNothing <$> tryReadMVar killMv) $ withSocket ctx Sub (\sock -> do
setLinger (restrict 0) sock
connect sock $ T.unpack endpoint connect sock $ T.unpack endpoint
debugM "QuoteSource.Client" $ "Tickers: " ++ show tickers debugM "QuoteSource.Client" $ "Tickers: " ++ show tickers
mapM_ (subscribe sock . encodeUtf8) tickers mapM_ (subscribe sock . encodeUtf8) tickers

1
src/ATrade/QuoteSource/Server.hs

@ -82,6 +82,7 @@ serverThread state = do
startQuoteSourceServer :: BoundedChan QuoteSourceServerData -> Context -> T.Text -> IO QuoteSourceServer startQuoteSourceServer :: BoundedChan QuoteSourceServerData -> Context -> T.Text -> IO QuoteSourceServer
startQuoteSourceServer chan c ep = do startQuoteSourceServer chan c ep = do
sock <- socket c Pub sock <- socket c Pub
setLinger (restrict 0) sock
bind sock $ T.unpack ep bind sock $ T.unpack ep
tid <- myThreadId tid <- myThreadId
hbTid <- forkIO $ forever $ do hbTid <- forkIO $ forever $ do

Loading…
Cancel
Save