@@ -21,8 +21,7 @@ module Ntp.Client
2121import Universum hiding (Last , catch )
2222
2323import Control.Concurrent (threadDelay )
24- import Control.Concurrent.Async (async , cancel , concurrently_ , race ,
25- wait , withAsync )
24+ import Control.Concurrent.Async (async , concurrently_ , race )
2625import Control.Concurrent.STM (TVar , check , modifyTVar' , retry )
2726import Control.Exception (Exception , IOException , catch , handle )
2827import Control.Monad (forever )
@@ -148,11 +147,6 @@ updateStatus cli = updateStatus' cli fn
148147 , (Wlog. Info , sformat (" Evaluated clock offset " % shown% " mcs" ) offset)
149148 )
150149
151- -- |
152- -- Internal commands raised by the send loop.
153- data NtpClientCmd = SendRequest
154- deriving Eq
155-
156150-- |
157151-- Every `ntpPollDelay` we send a request to the list of `ntpServers`. Before
158152-- sending a request, we put `NtpSyncPending` to `ncState`. After sending
@@ -162,32 +156,20 @@ data NtpClientCmd = SendRequest
162156-- drift.
163157sendLoop :: NtpClient -> [Addresses ] -> IO ()
164158sendLoop cli addrs = do
165-
166-
167159 let respTimeout = ntpResponseTimeout (ncSettings cli)
168160 let poll = ntpPollDelay (ncSettings cli)
169161
170- () <- withAsync
171- (do
172- -- wait for responses and update status
173- _ <- timeout respTimeout waitForResponses
174- updateStatus cli
175- -- after @'updateStatus'@ @'ntpStatus'@ is guaranteed to be
176- -- different from @'NtpSyncPending'@, now we can wait until it was
177- -- changed back to @'NtpSyncPending'@ to force a request.
178- waitForRequest
179- )
180- (\ a -> do
181- -- send packets and wait until end of poll delay
182- sock <- atomically $ readTVar $ ncSockets cli
183- pack <- mkNtpPacket
184- sendPacket sock pack addrs
185-
186- cmd <- timeout poll (wait a)
187- case cmd of
188- Nothing -> cancel a
189- Just _ -> return ()
190- )
162+ -- send packets and wait until end of poll delay
163+ sock <- atomically $ readTVar $ ncSockets cli
164+ pack <- mkNtpPacket
165+ sendPacket sock pack addrs
166+
167+ _ <- timeout respTimeout waitForResponses
168+ updateStatus cli
169+ -- after @'updateStatus'@ @'ntpStatus'@ is guaranteed to be
170+ -- different from @'NtpSyncPending'@, now we can wait until it was
171+ -- changed back to @'NtpSyncPending'@ to force a request.
172+ _ <- timeout poll waitForRequest
191173
192174 -- reset state & status before next loop
193175 atomically $ writeTVar (ncState cli) []
@@ -209,7 +191,7 @@ sendLoop cli addrs = do
209191 atomically $ do
210192 status <- readTVar $ ncStatus cli
211193 check (status == NtpSyncPending )
212- return SendRequest
194+ return ()
213195
214196
215197-- |
0 commit comments