Skip to content

Commit

Permalink
labeling threads
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Nov 5, 2024
1 parent 31c9d9d commit e901414
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
5 changes: 4 additions & 1 deletion warp-quic/Network/Wai/Handler/WarpQUIC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ quicApp settings app ii conn = do
let runX
| "h3" `BS.isPrefixOf` appProto = H3.run
| otherwise = HQ.run
runX conn conf $ http2server settings ii transport addr app
label
| "h3" `BS.isPrefixOf` appProto = "Warp HTTP/3"
| otherwise = "Warp HQ"
runX conn conf $ http2server label settings ii transport addr app
10 changes: 7 additions & 3 deletions warp/Network/Wai/Handler/Warp/HTTP2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Network.Wai.Handler.Warp.HTTP2 (
import qualified Data.ByteString as BS
import Data.IORef (readIORef)
import qualified Data.IORef as I
import GHC.Conc.Sync (labelThread, myThreadId)
import qualified Network.HTTP2.Frame as H2
import qualified Network.HTTP2.Server as H2
import Network.Socket (SockAddr)
Expand Down Expand Up @@ -69,7 +70,7 @@ http2 settings ii conn transport app peersa th bs = do
checkTLS
setConnHTTP2 conn True
H2.run H2.defaultServerConfig conf $
http2server settings ii transport peersa app
http2server "Warp HTTP/2" settings ii transport peersa app
where
checkTLS = case transport of
TCP -> return () -- direct
Expand All @@ -80,13 +81,16 @@ http2 settings ii conn transport app peersa th bs = do
--
-- Since 3.3.11
http2server
:: S.Settings
:: String
-> S.Settings
-> InternalInfo
-> Transport
-> SockAddr
-> Application
-> H2.Server
http2server settings ii transport addr app h2req0 aux0 response = do
http2server label settings ii transport addr app h2req0 aux0 response = do
tid <- myThreadId
labelThread tid (label ++ " http2server " ++ show addr)
req <- toWAIRequest h2req0 aux0
ref <- I.newIORef Nothing
eResponseReceived <- UnliftIO.tryAny $ app req $ \rsp -> do
Expand Down
8 changes: 7 additions & 1 deletion warp/Network/Wai/Handler/Warp/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import qualified Data.ByteString as S
import Data.IORef (newIORef, readIORef)
import Data.Streaming.Network (bindPortTCP)
import Foreign.C.Error (Errno (..), eCONNABORTED, eMFILE)
import GHC.Conc.Sync (labelThread, myThreadId)
import GHC.IO.Exception (IOErrorType (..), IOException (..))
import Network.Socket (
SockAddr,
Expand Down Expand Up @@ -327,7 +328,9 @@ fork
-> Counter
-> InternalInfo
-> IO ()
fork set mkConn addr app counter ii = settingsFork set $ \unmask ->
fork set mkConn addr app counter ii = settingsFork set $ \unmask -> do
tid <- myThreadId
labelThread tid "Warp just forked"
-- Call the user-supplied on exception code if any
-- exceptions are thrown.
--
Expand Down Expand Up @@ -386,6 +389,7 @@ serveConnection
-> IO ()
serveConnection conn ii th origAddr transport settings app = do
-- fixme: Upgrading to HTTP/2 should be supported.
tid <- myThreadId
(h2, bs) <-
if isHTTP2 transport
then return (True, "")
Expand All @@ -396,8 +400,10 @@ serveConnection conn ii th origAddr transport settings app = do
else return (False, bs0)
if settingsHTTP2Enabled settings && h2
then do
labelThread tid ("Warp HTTP/2 " ++ show origAddr)
http2 settings ii conn transport app origAddr th bs
else do
labelThread tid ("Warp HTTP/1.1 " ++ show origAddr)
http1 settings ii conn transport app origAddr th bs
where
recv4 bs0 = do
Expand Down

0 comments on commit e901414

Please sign in to comment.