diff --git a/example/Main.hs b/example/Main.hs index 71d5d4425d5f7805369f84e46bb1374e22973db4..d0612ac76fdf474ccc0f1f2ad7859d3360016800 100644 --- a/example/Main.hs +++ b/example/Main.hs @@ -7,7 +7,7 @@ import Quasar.Wayland.Client main :: IO () main = do - withResourceManagerM do + withRootResourceManager do traceIO "Connecting" client <- connectWaylandClient traceIO "Connected" diff --git a/flake.lock b/flake.lock index cd0a41f5074db0a30850aeb2dce2da50cd10fcd9..599e5dbc9d86de7944a18d8ead209af8a4807ee5 100644 --- a/flake.lock +++ b/flake.lock @@ -23,11 +23,11 @@ }, "locked": { "host": "git.c3pb.de", - "lastModified": 1631852696, - "narHash": "sha256-sM5h2IHVyB0kKMNz44042D6QVvsTyUhaOCYkdcEjabQ=", + "lastModified": 1638315058, + "narHash": "sha256-SA99IShGlTc3IkcqG5YP/lnSyTWWHFIdvci5pWR8BrI=", "owner": "jens", "repo": "quasar", - "rev": "862976c067cc41435e1087def16dfb86c57b317b", + "rev": "7f163062fd2dc98041b5149c5ab23fd8cedde7e6", "type": "gitlab" }, "original": { @@ -46,11 +46,11 @@ }, "locked": { "host": "git.c3pb.de", - "lastModified": 1631899417, - "narHash": "sha256-qSD1O3x/oCgrm6v1GGSO2d+rO0jMs2zi8yASXhPyHN0=", + "lastModified": 1638330205, + "narHash": "sha256-vVdNLDtS7mmj5FLJ7/lL0mJ9r05ZLhJQoRAlmDa7OC4=", "owner": "jens", "repo": "quasar-network", - "rev": "fda985686d4003c85c53bbb1654cf5324ae4e7c2", + "rev": "12c98e410f4a6d96b9ea2390da1edc6d026ad7ae", "type": "gitlab" }, "original": { diff --git a/src/Quasar/Wayland/Connection.hs b/src/Quasar/Wayland/Connection.hs index 5b5f1dbf10a75e302ad3c332b68eb151b996a9e7..4c91fb1034f0c3190fa0c7cacbf3c722ccdf5a99 100644 --- a/src/Quasar/Wayland/Connection.hs +++ b/src/Quasar/Wayland/Connection.hs @@ -51,18 +51,16 @@ newWaylandConnection initializeProtocolAction socket = do registerDisposeAction $ closeConnection connection - runUnlimitedAsync do - connectionThread connection $ sendThread connection - connectionThread connection $ receiveThread connection + connectionThread connection $ sendThread connection + connectionThread connection $ receiveThread connection pure (result, connection) -connectionThread :: MonadAsync m => WaylandConnection s -> IO () -> m () -connectionThread connection work = async_ $ liftIO $ work `catches` [ignoreCancelTask, traceAndDisposeConnection] +connectionThread :: MonadResourceManager m => WaylandConnection s -> IO () -> m () +connectionThread connection work = asyncWithHandler_ traceAndDisposeConnection $ liftIO $ work where - ignoreCancelTask :: Handler IO a - ignoreCancelTask = Handler (throwM :: CancelTask -> IO a) - traceAndDisposeConnection = Handler (\(ex :: SomeException) -> traceIO (displayException ex) >> void (dispose connection)) + traceAndDisposeConnection :: SomeException -> IO () + traceAndDisposeConnection ex = traceIO (displayException ex) >> void (dispose connection) sendThread :: WaylandConnection s -> IO () sendThread connection = forever do @@ -83,8 +81,5 @@ receiveThread connection = forever do feedInput connection.protocolHandle bytes -closeConnection :: WaylandConnection s -> IO (Awaitable ()) -closeConnection connection = do - -- gracefulClose may fail but guarantees that the socket is deallocated - Socket.close connection.socket `catch` \(_ :: SomeException) -> pure () - pure $ pure () +closeConnection :: WaylandConnection s -> IO () +closeConnection connection = Socket.close connection.socket