@@ -45,14 +45,16 @@ bytesPerRead :: Int
4545bytesPerRead = 4096
4646
4747-- | Default action value for 'Connection'
48−socketConnection :: Socket -> ReceiveBuffer -> Connection
49−socketConnection s buf = Connection
50− { connSendMany = Sock.sendMany s
51− , connSendAll = Sock.sendAll s
52− , connSendFile = sendFile s
53− , connClose = sClose s
54− , connRecv = receive s buf bytesPerRead
55− }
48+socketConnection :: Socket -> IO Connection
49+socketConnection s = do
50+ buf <- allocateRecvBuffer bytesPerRead
51+ return Connection {
52+ connSendMany = Sock.sendMany s
53+ , connSendAll = Sock.sendAll s
54+ , connSendFile = sendFile s
55+ , connClose = sClose s >> freeRecvBuffer buf
56+ , connRecv = receive s buf bytesPerRead
57+ }
5658
5759sendFile :: Socket -> FilePath -> Integer -> Integer -> IO () -> [ByteString] -> Cleaner -> IO ()
5860#if SENDFILEFD
@@ -111,9 +113,9 @@ runSettingsSocket set socket app =
111113 where
112114 getConn = do
113115 (s, sa) <- accept socket
114− buf <- allocateRecvBuffer bytesPerRead
115116 setSocketCloseOnExec socket
116− return (socketConnection s buf, sa)
117+ conn <- socketConnection s
118+ return (conn, sa)
117119
118120runSettingsConnection :: Settings -> IO (Connection, SockAddr) -> Application -> IO ()
119121runSettingsConnection set getConn app = runSettingsConnectionMaker set getConnMaker app