Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quasar-wayland
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
quasar-wayland
Commits
5164e9a1
Commit
5164e9a1
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Implement running ProtocolM from STM
parent
b70002ea
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Quasar/Wayland/Protocol.hs
+1
-0
1 addition, 0 deletions
src/Quasar/Wayland/Protocol.hs
src/Quasar/Wayland/Protocol/Core.hs
+19
-9
19 additions, 9 deletions
src/Quasar/Wayland/Protocol/Core.hs
with
20 additions
and
9 deletions
src/Quasar/Wayland/Protocol.hs
+
1
−
0
View file @
5164e9a1
...
...
@@ -24,6 +24,7 @@ module Quasar.Wayland.Protocol (
-- ** Low-level protocol interaction
ProtocolM
,
runProtocolTransaction
,
runProtocolM
,
Object
,
newObject
,
...
...
This diff is collapsed.
Click to expand it.
src/Quasar/Wayland/Protocol/Core.hs
+
19
−
9
View file @
5164e9a1
...
...
@@ -23,6 +23,7 @@ module Quasar.Wayland.Protocol.Core (
feedInput
,
setException
,
takeOutbox
,
runProtocolTransaction
,
runProtocolM
,
-- * Low-level protocol interaction
...
...
@@ -425,11 +426,12 @@ initializeProtocol wlDisplayCallback initializationAction = do
wlDisplay
::
Object
s
wl_display
wlDisplay
=
Object
1
wlDisplayCallback
-- | Entry point to run a protocol action, effectively an 'atomically' with correct error handling.
-- | Run a protocol action in 'IO'. If an exception occurs, it is stored as a protocol failure and is then
-- re-thrown.
--
-- Throws an exception,
when
the protocol
reaches or is
in a failed
(/error)
state.
runProtocol
M
::
(
MonadIO
m
,
MonadThrow
m
)
=>
ProtocolHandle
s
->
ProtocolM
s
a
->
m
a
runProtocol
M
(
ProtocolHandle
stateVar
)
action
=
do
-- Throws an exception,
if
the protocol
is already
in a failed state.
runProtocol
Transaction
::
MonadIO
m
=>
ProtocolHandle
s
->
ProtocolM
s
a
->
m
a
runProtocol
Transaction
(
ProtocolHandle
stateVar
)
action
=
do
result
<-
liftIO
$
atomically
do
readTVar
stateVar
>>=
\
case
-- Protocol is already in a failed state
...
...
@@ -444,25 +446,33 @@ runProtocolM (ProtocolHandle stateVar) action = do
Right
result
->
do
pure
(
Right
result
)
-- Transaction is committed, rethrow exception if the action failed
either
throwM
pure
result
either
(
liftIO
.
throwM
)
pure
result
-- | Run a 'ProtocolM'-action inside 'STM'.
--
-- Exceptions are not handled and reset the transaction (as usual with STM).
--
-- Throws an exception, if the protocol is already in a failed state.
runProtocolM
::
ProtocolHandle
s
->
ProtocolM
s
a
->
STM
a
runProtocolM
protocol
action
=
either
throwM
(
runReaderT
action
)
=<<
readTVar
protocol
.
stateVar
-- | Feed the protocol newly received data.
feedInput
::
(
IsSide
s
,
MonadIO
m
,
MonadThrow
m
)
=>
ProtocolHandle
s
->
ByteString
->
m
()
feedInput
protocol
bytes
=
runProtocol
M
protocol
do
-- Exposing MonadIO instead of STM to the outside and using `runProtocol
M
` here enforces correct exception handling.
feedInput
protocol
bytes
=
runProtocol
Transaction
protocol
do
-- Exposing MonadIO instead of STM to the outside and using `runProtocol
Transaction
` here enforces correct exception handling.
modifyProtocolVar
(
.
bytesReceivedVar
)
(
+
fromIntegral
(
BS
.
length
bytes
))
modifyProtocolVar
(
.
inboxDecoderVar
)
(`
pushChunk
`
bytes
)
receiveMessages
-- | Set the protocol to a failed state, e.g. when the socket closed unexpectedly.
setException
::
(
Exception
e
,
MonadIO
m
,
MonadThrow
m
)
=>
ProtocolHandle
s
->
e
->
m
()
setException
protocol
ex
=
runProtocol
M
protocol
$
throwM
ex
setException
protocol
ex
=
runProtocol
Transaction
protocol
$
throwM
ex
-- | Take data that has to be sent. Blocks until data is available.
takeOutbox
::
(
MonadIO
m
,
MonadThrow
m
)
=>
ProtocolHandle
s
->
m
(
BSL
.
ByteString
)
takeOutbox
protocol
=
runProtocol
M
protocol
do
takeOutbox
protocol
=
runProtocol
Transaction
protocol
do
mOutboxData
<-
stateProtocolVar
(
.
outboxVar
)
(
\
mOutboxData
->
(
mOutboxData
,
Nothing
))
outboxData
<-
maybe
(
lift
retry
)
pure
mOutboxData
let
sendData
=
runPut
outboxData
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment