Skip to content

Commit

Permalink
Put pings at the head of the send queue
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Jul 25, 2024
1 parent a3ec982 commit 6dbde8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Client/Network/Async.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Client.Network.Async
, NetworkEvent(..)
, createConnection
, Client.Network.Async.send
, sendNext
, Client.Network.Async.recv
, upgrade

Expand Down Expand Up @@ -121,6 +122,13 @@ instance Exception TerminationReason where
send :: NetworkConnection -> ByteString -> IO ()
send c msg = atomically (writeTQueue (connOutQueue c) msg)

-- | Insert a message to be transmitted on the network connection immediately.
-- These messages are sent unmodified. The message should contain a
-- newline terminator. This should be used for very high priority messages
-- that must not get stuck in the queue.
sendNext :: NetworkConnection -> ByteString -> IO ()
sendNext c msg = atomically (unGetTQueue (connOutQueue c) msg)

recv :: NetworkConnection -> STM [NetworkEvent]
recv = flushTQueue . connInQueue

Expand Down
7 changes: 6 additions & 1 deletion src/Client/State/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ defaultChannelTypes = "#&"
csNick :: Lens' NetworkState Identifier
csNick = csUserInfo . uiNick

-- | Transmit a 'RawIrcMsg' with high priority. This is done without
-- the message splitting that 'sendMsg' usually does.
sendMsgNext :: NetworkState -> RawIrcMsg -> IO ()
sendMsgNext cs msg = send (view csSocket cs) (renderRawIrcMsg msg)

-- | Transmit a 'RawIrcMsg' on the connection associated
-- with the given network. For @PRIVMSG@ and @NOTICE@ overlong
-- commands are detected and transmitted as multiple messages.
Expand Down Expand Up @@ -1229,7 +1234,7 @@ applyTimedAction action cs =

TimedSendPing ->
do now <- getCurrentTime
sendMsg cs (ircPing ["ping"])
sendMsgNext cs (ircPing ["ping"])
return $! set csNextPingTime (Just $! addUTCTime 60 now)
$ set csPingStatus (PingSent now) cs

Expand Down

0 comments on commit 6dbde8c

Please sign in to comment.