Skip to content

Commit

Permalink
naming threads
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Oct 30, 2024
1 parent 79ddfb0 commit 4ad3835
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Network/QUIC/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module Network.QUIC.Common where

import qualified Network.Socket as NS

import Control.Concurrent
import GHC.Conc.Sync

import Network.QUIC.Connection
import Network.QUIC.Parameters
import Network.QUIC.Types
Expand All @@ -22,3 +25,11 @@ defaultPacketSize _ = defaultQUICPacketSizeForIPv4
maximumPacketSize :: NS.SockAddr -> Int
maximumPacketSize NS.SockAddrInet6{} = 1500 - 40 - 8 -- fixme
maximumPacketSize _ = 1500 - 20 - 8 -- fixme

labelMe :: String -> IO ()
labelMe name = do
tid <- myThreadId
mlabel <- threadLabel tid
case mlabel of
Nothing -> labelThread tid name
Just _ -> return ()
8 changes: 7 additions & 1 deletion Network/QUIC/Server/Reader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Network.Socket (Socket)
import qualified Network.Socket.ByteString as NSB
import qualified System.IO.Error as E

import Network.QUIC.Common
import Network.QUIC.Config
import Network.QUIC.Connection
import Network.QUIC.Exception
Expand Down Expand Up @@ -59,7 +60,11 @@ newDispatch ServerConfig{..} =
<*> newIORef emptyRecvQDict
<*> newAcceptQ
where
conf = CT.defaultConfig{CT.tokenLifetime = scTicketLifetime}
conf =
CT.defaultConfig
{ CT.tokenLifetime = scTicketLifetime
, CT.threadName = "QUIC token manager"
}

clearDispatch :: Dispatch -> IO ()
clearDispatch d = CT.killTokenManager $ tokenMgr d
Expand Down Expand Up @@ -144,6 +149,7 @@ runDispatcher d conf mysock = forkIO $ dispatcher d conf mysock

dispatcher :: Dispatch -> ServerConfig -> Socket -> IO ()
dispatcher d conf mysock = handleLogUnit logAction $ do
labelMe "QUIC dispatcher"
forever $ do
(peersa, bs, cmsgs, _) <- safeRecv $ NSB.recvMsg mysock 2048 2048 0
now <- getTimeMicrosecond
Expand Down
5 changes: 4 additions & 1 deletion Network/QUIC/Server/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import Network.QUIC.Types
-- in a new lightweight thread.
run :: ServerConfig -> (Connection -> IO ()) -> IO ()
run conf server = NS.withSocketsDo $ handleLogUnit debugLog $ do
labelMe "QUIC run"
baseThreadId <- myThreadId
E.bracket setup teardown $ \(dispatch, _, _) -> do
onServerReady $ scHooks conf
Expand Down Expand Up @@ -68,6 +69,7 @@ run conf server = NS.withSocketsDo $ handleLogUnit debugLog $ do
-- in a new lightweight thread.
runWithSockets :: [NS.Socket] -> ServerConfig -> (Connection -> IO ()) -> IO ()
runWithSockets ssas conf server = NS.withSocketsDo $ handleLogUnit debugLog $ do
labelMe "QUIC runWithSockets"
baseThreadId <- myThreadId
E.bracket setup teardown $ \(dispatch, _) -> do
onServerReady $ scHooks conf
Expand All @@ -92,7 +94,8 @@ runWithSockets ssas conf server = NS.withSocketsDo $ handleLogUnit debugLog $ do
-- And the exception should be ignored.
runServer
:: ServerConfig -> (Connection -> IO ()) -> Dispatch -> ThreadId -> Accept -> IO ()
runServer conf server0 dispatch baseThreadId acc =
runServer conf server0 dispatch baseThreadId acc = do
labelMe "QUIC runServer"
E.bracket open clse $ \(ConnRes conn myAuthCIDs _reader) ->
handleLogUnit (debugLog conn) $ do
let conf' =
Expand Down

0 comments on commit 4ad3835

Please sign in to comment.