Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit fe963f8

Browse files
author
Hiroto Shioi
committed
Fix the use of term client/server according to the spec
1 parent 1093221 commit fe963f8

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-| This executable act as an server of an IPC protocol
1+
{-| This executable act as an client of an IPC protocol
22
|-}
33

44
{-# LANGUAGE OverloadedStrings #-}
@@ -18,16 +18,16 @@ import System.IO (BufferMode (..), hClose, hSetBuffering)
1818
port :: Port
1919
port = Port 8090
2020

21-
-- | Launches the IPC server, the one responses to the message from the client.
21+
-- | Launches the IPC client, the one responses to the message from the server.
2222
--
23-
-- Client will pass its handle via environment variable.
24-
-- The server will then decodes the handle and launches IPC listener.
25-
-- It then respond to the client with the handle it has been given.
23+
-- Server will pass its handle via environment variable.
24+
-- The client will then decodes the handle and launches IPC listener.
25+
-- It then respond to the server with the handle it has been given.
2626
--
27-
-- Because of this, the client must the be the one to execute this function (see @exampleWithProcess@).
28-
-- Call this function directly (ex. @stack exec node-ipc haskell@) will throw an error
29-
-- since there wouldn't be an handle that server will be able to use to communicate with
30-
-- the client.
27+
-- Because of this, the server must the be the one to execute this function (see @exampleWithProcess@).
28+
-- Calling this function directly (ex. @stack exec node-ipc haskell@) will throw an error
29+
-- since there wouldn't be an handle that client will be able to use to communicate with
30+
-- the server.
3131
main :: IO ()
3232
main = do
3333
(cmd:_) <- getArgs
@@ -38,17 +38,17 @@ main = do
3838
where
3939
acquire :: IO Handle
4040
acquire = do
41-
-- Lookup the Handle that the client has set
42-
clientWHandle <- getHandleFromEnv "FD_WRITE_HANDLE"
43-
hSetBuffering clientWHandle LineBuffering
44-
return clientWHandle
41+
-- Lookup the Handle that the server has set
42+
serverWHandle <- getHandleFromEnv "FD_WRITE_HANDLE"
43+
hSetBuffering serverWHandle LineBuffering
44+
return serverWHandle
4545

4646
restore :: Handle -> IO ()
4747
restore = hClose
4848

4949
action :: Handle -> IO ()
50-
action clientWHandle = do
51-
let clientWriteHandle = WriteHandle clientWHandle
50+
action serverWHandle = do
51+
let serverWriteHandle = WriteHandle serverWHandle
5252
let serverReadHandle = ReadHandle stdin
53-
startIPC SingleMessage serverReadHandle clientWriteHandle port
53+
startIPC SingleMessage serverReadHandle serverWriteHandle port
5454

File renamed without changes.

cardano-shell.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ executable node-ipc
114114
other-modules:
115115
Paths_cardano_shell
116116
hs-source-dirs:
117-
app/NodeIPCServer
117+
app/NodeIPCClient
118118
ghc-options: -threaded -rtsopts -with-rtsopts=-N
119119
build-depends:
120120
base >=4.7 && <5

src/Cardano/Shell/NodeIPC/Example.hs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
-- This allows the two proccesses to send the message to the other while
1616
-- reading the response that other had sent.
1717
-}
18+
1819
module Cardano.Shell.NodeIPC.Example
1920
( exampleWithFD
2021
, exampleWithProcess
@@ -61,31 +62,31 @@ nodePort = Port 8090
6162
exampleWithFD :: MsgIn -> IO (MsgOut, MsgOut)
6263
exampleWithFD msgin = do
6364

64-
(clientReadHandle, clientWriteHandle) <- getReadWriteHandles
65+
(serverReadHandle, serverWriteHandle) <- getReadWriteHandles
6566

6667
(_, 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
7172
`concurrently`
72-
receieveMessages clientReadHandle
73+
receieveMessages serverReadHandle
7374

7475
return responses
7576

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.
7778
--
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@
8182
exampleWithProcess :: MsgIn -> IO (MsgOut, MsgOut)
8283
exampleWithProcess msg = bracket acquire restore (action msg)
8384
where
8485
acquire :: IO (ReadHandle, Handle)
8586
acquire = do
8687
(rFd, wFd) <- createPipeFd
8788
-- 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
8990
setEnv "FD_WRITE_HANDLE" (show wFd)
9091
readHandle <- ReadHandle <$> fdToHandle rFd
9192
-- Since closeFd only exists in 'unix' library,
@@ -110,11 +111,11 @@ exampleWithProcess msg = bracket acquire restore (action msg)
110111

111112
-- | Read message wigh given 'ReadHandle'
112113
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
118119
return (started, reply)
119120

120121
getHandleFromEnv :: String -> IO Handle

0 commit comments

Comments
 (0)