15
15
-- This allows the two proccesses to send the message to the other while
16
16
-- reading the response that other had sent.
17
17
-}
18
+
18
19
module Cardano.Shell.NodeIPC.Example
19
20
( exampleWithFD
20
21
, exampleWithProcess
@@ -61,31 +62,31 @@ nodePort = Port 8090
61
62
exampleWithFD :: MsgIn -> IO (MsgOut , MsgOut )
62
63
exampleWithFD msgin = do
63
64
64
- (clientReadHandle, clientWriteHandle ) <- getReadWriteHandles
65
+ (serverReadHandle, serverWriteHandle ) <- getReadWriteHandles
65
66
66
67
(_, responses) <- do
67
- (serverReadHandle, serverWriteHandle ) <- getReadWriteHandles
68
- -- Send message to server
69
- sendMessage serverWriteHandle msgin
70
- startIPC SingleMessage serverReadHandle clientWriteHandle nodePort
68
+ (clientReadHandle, clientWriteHandle ) <- getReadWriteHandles
69
+ -- Send message to client
70
+ sendMessage clientWriteHandle msgin
71
+ startIPC SingleMessage clientReadHandle serverWriteHandle nodePort
71
72
`concurrently`
72
- receieveMessages clientReadHandle
73
+ receieveMessages serverReadHandle
73
74
74
75
return responses
75
76
76
- -- | Example of an IPC client that is using haskell executable as an server.
77
+ -- | Example of an IPC server that is using haskell executable as an server.
77
78
--
78
- -- This will be the client , the one which sends the message (such as @Ping@, @QueryPort@)
79
- -- to get the response from the other .
80
- -- The server is executed via @stack exec node-ipc haskell@
79
+ -- This will be the server , the one which sends the message (such as @Ping@, @QueryPort@)
80
+ -- to get the response from the client .
81
+ -- The client is executed via @stack exec node-ipc haskell@
81
82
exampleWithProcess :: MsgIn -> IO (MsgOut , MsgOut )
82
83
exampleWithProcess msg = bracket acquire restore (action msg)
83
84
where
84
85
acquire :: IO (ReadHandle , Handle )
85
86
acquire = do
86
87
(rFd, wFd) <- createPipeFd
87
88
-- Set the write file descriptor to the envrionment variable
88
- -- the server will look this up, and use it to talk the client
89
+ -- the client will look this up, and use it to talk the server
89
90
setEnv " FD_WRITE_HANDLE" (show wFd)
90
91
readHandle <- ReadHandle <$> fdToHandle rFd
91
92
-- Since closeFd only exists in 'unix' library,
@@ -110,11 +111,11 @@ exampleWithProcess msg = bracket acquire restore (action msg)
110
111
111
112
-- | Read message wigh given 'ReadHandle'
112
113
receieveMessages :: ReadHandle -> IO (MsgOut , MsgOut )
113
- receieveMessages clientReadHandle = do
114
- let readClientMessage :: IO MsgOut
115
- readClientMessage = readMessage clientReadHandle
116
- started <- readClientMessage -- Started
117
- reply <- readClientMessage -- Reply
114
+ receieveMessages serverReadHandle = do
115
+ let readServerMessage :: IO MsgOut
116
+ readServerMessage = readMessage serverReadHandle
117
+ started <- readServerMessage -- Started
118
+ reply <- readServerMessage -- Reply
118
119
return (started, reply)
119
120
120
121
getHandleFromEnv :: String -> IO Handle
0 commit comments