diff --git a/src/Quasar/Wayland/Connection.hs b/src/Quasar/Wayland/Connection.hs index a4285c907d7f7db510a99b8e3b255e7ca2368e5d..faa8c794cc41d2e1e070a6afc80b492baacae8dd 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