From 1f2f984d367cb65619d7adbb8f705f0dd3ee382e Mon Sep 17 00:00:00 2001 From: Jens Nolte <git@queezle.net> Date: Thu, 23 Dec 2021 13:51:19 +0100 Subject: [PATCH] Close file descriptors after sending --- src/Quasar/Wayland/Connection.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Quasar/Wayland/Connection.hs b/src/Quasar/Wayland/Connection.hs index a4285c9..faa8c79 100644 --- a/src/Quasar/Wayland/Connection.hs +++ b/src/Quasar/Wayland/Connection.hs @@ -23,6 +23,7 @@ import Quasar import Quasar.Prelude import Quasar.Wayland.Protocol import Quasar.Wayland.Utils.Socket +import System.Posix.IO (closeFd) import System.Posix.Types (Fd) @@ -86,16 +87,17 @@ connectionThread connection work = asyncWithHandler traceAndDisposeConnection $ traceAndDisposeConnection ex = traceIO (displayException ex) >> void (dispose connection) sendThread :: WaylandConnection s -> IO () -sendThread connection = forever do +sendThread connection = mask_ $ forever do (msg, fds) <- takeOutbox connection.protocolHandle + finally + do + traceIO $ "Sending " <> show (BSL.length msg) <> " bytes" - let msgLength = fromIntegral (BSL.length msg) - - traceIO $ "Sending " <> show msgLength <> " bytes" - - -- TODO limit max fds - send msgLength (BSL.toChunks msg) fds + -- TODO limit max fds + send (fromIntegral (BSL.length msg)) (BSL.toChunks msg) fds + do + mapM closeFd fds where send :: Int -> [BS.ByteString] -> [Fd] -> IO () send remaining chunks fds = do -- GitLab