-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runtime): add send doesn't work yet, because we always send to o…
…urselves
- Loading branch information
1 parent
46567c1
commit 98ab4bc
Showing
7 changed files
with
159 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/runtime-prototype/src/StuntDouble/EventLoop/InboundHandler.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module StuntDouble.EventLoop.InboundHandler where | ||
|
||
import qualified Data.Map as Map | ||
import Control.Monad | ||
import Control.Exception | ||
import Control.Concurrent.Async | ||
import Control.Concurrent.STM | ||
|
||
import StuntDouble.EventLoop.State | ||
import StuntDouble.EventLoop.Event | ||
import StuntDouble.EventLoop.Transport | ||
import StuntDouble.Reference | ||
import StuntDouble.Message | ||
|
||
------------------------------------------------------------------------ | ||
|
||
handleInbound :: LoopState -> IO () | ||
handleInbound ls = forever go | ||
where | ||
go = do | ||
e <- transportReceive (loopStateTransport ls) | ||
atomically $ do | ||
responses <- readTVar (loopStateResponses ls) | ||
case Map.lookup (envelopeCorrelationId e) responses of | ||
Nothing -> | ||
writeTBQueue (loopStateQueue ls) (Receive (Request e)) | ||
Just respTMVar -> | ||
writeTBQueue (loopStateQueue ls) (Response (Reply respTMVar e)) |
57 changes: 0 additions & 57 deletions
57
src/runtime-prototype/src/StuntDouble/EventLoop/RequestHandler.hs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 39 additions & 2 deletions
41
src/runtime-prototype/src/StuntDouble/EventLoop/Transport.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,47 @@ | ||
module StuntDouble.EventLoop.Transport where | ||
|
||
import Control.Exception | ||
import Control.Concurrent.Async | ||
import System.IO | ||
import System.IO.Error | ||
import System.Posix.Files | ||
|
||
import StuntDouble.EventLoop.Event | ||
import StuntDouble.Reference | ||
import StuntDouble.Message | ||
|
||
------------------------------------------------------------------------ | ||
|
||
data Transport m = Transport | ||
{ send :: Envelope -> m () | ||
, receive :: m Envelope | ||
{ transportSend :: Envelope -> m () | ||
, transportReceive :: m Envelope | ||
} | ||
|
||
------------------------------------------------------------------------ | ||
|
||
namedPipeTransport :: FilePath -> IO (Transport IO) | ||
namedPipeTransport fp = do | ||
catchJust | ||
(\e -> if isAlreadyExistsErrorType (ioeGetErrorType e) | ||
then Just () | ||
else Nothing) | ||
(createNamedPipe fp (namedPipeMode `unionFileModes` | ||
ownerReadMode `unionFileModes` | ||
ownerWriteMode)) | ||
return | ||
h <- openFile fp ReadWriteMode | ||
hSetBuffering h LineBuffering | ||
return Transport { transportSend = hPutStrLn h . show | ||
, transportReceive = fmap read (hGetLine h) | ||
} | ||
|
||
------------------------------------------------------------------------ | ||
|
||
test :: IO () | ||
test = do | ||
t <- namedPipeTransport "/tmp/test_request.pipe" | ||
let e = Envelope (RemoteRef "from" 0) (Message "msg") (RemoteRef "to" 1) 0 | ||
a <- async (transportSend t e) | ||
e' <- transportReceive t | ||
cancel a | ||
assert (e' == e) (return ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters