@@ -58,17 +58,25 @@ import Network.Socket (fdSocket)
60-- | Creating 'Connection' for plain HTTP based on a given socket.
60-- | Creating 'Connection' for plain HTTP based on a given socket.
61−socketConnection :: Socket -> IO Connection
61+socketConnection :: Settings -> Socket -> IO Connection
62−socketConnection s = do
62+socketConnection set s = do
63 bufferPool <- newBufferPool
63 bufferPool <- newBufferPool
64 writeBuf <- allocateBuffer bufferSize
64 writeBuf <- allocateBuffer bufferSize
65 let sendall = Sock.sendAll s
65 let sendall = Sock.sendAll s
66+ isH2 <- newIORef False -- HTTP/1.x
66 return Connection {
67 return Connection {
67 connSendMany = Sock.sendMany s
68 connSendMany = Sock.sendMany s
68 , connSendAll = sendall
69 , connSendAll = sendall
69 , connSendFile = sendFile s writeBuf bufferSize sendall
70 , connSendFile = sendFile s writeBuf bufferSize sendall
70#if MIN_VERSION_network(3,1,1)
71#if MIN_VERSION_network(3,1,1)
74+ let tm = if h2 then settingsGracefulCloseTimeout2 set
75+ else settingsGracefulCloseTimeout1 set
71− , connClose = gracefulClose s 5000
79+ gracefulClose s tm
73 , connClose = close s
81 , connClose = close s
@@ -77,6 +85,7 @@ socketConnection s = do
77 , connRecvBuf = receiveBuf s
85 , connRecvBuf = receiveBuf s
78 , connWriteBuffer = writeBuf
86 , connWriteBuffer = writeBuf
79 , connBufferSize = bufferSize
87 , connBufferSize = bufferSize
82-- | Run an 'Application' on the given port.
91-- | Run an 'Application' on the given port.
@@ -138,7 +147,7 @@ runSettingsSocket set socket app = do
138 setSocketCloseOnExec s
147 setSocketCloseOnExec s
139 -- NoDelay causes an error for AF_UNIX.
148 -- NoDelay causes an error for AF_UNIX.
140 setSocketOption s NoDelay 1 `E.catch` \(E.SomeException _) -> return ()
149 setSocketOption s NoDelay 1 `E.catch` \(E.SomeException _) -> return ()
141− conn <- socketConnection s
150+ conn <- socketConnection set s
142 return (conn, sa)
151 return (conn, sa)
144 closeListenSocket = close socket
153 closeListenSocket = close socket
@@ -344,6 +353,7 @@ serveConnection conn ii th origAddr transport settings app = do
344 let recvN = wrappedRecvN th istatus (settingsSlowlorisSize settings) rawRecvN
353 let recvN = wrappedRecvN th istatus (settingsSlowlorisSize settings) rawRecvN
345 -- fixme: origAddr
354 -- fixme: origAddr
356+ setConnHTTP2 conn True
347 http2 conn transport ii origAddr settings recvN app
357 http2 conn transport ii origAddr settings recvN app
349 src <- mkSource (wrappedRecv conn th istatus (settingsSlowlorisSize settings))
359 src <- mkSource (wrappedRecv conn th istatus (settingsSlowlorisSize settings))