Copyright | (c) Dong Han 2018 |
---|---|
License | BSD |
Maintainer | winterland1989@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This module provides an API for creating IPC servers and clients. IPC Support is implemented with named pipes on Windows, and UNIX domain sockets on other operating systems.
On UNIX, the local domain is also known as the UNIX domain. The path is a filesystem path name. It gets truncated to sizeof(sockaddr_un.sun_path) - 1, which varies on different operating system between 91 and 107 bytes. The typical values are 107 on Linux and 103 on macOS. The path is subject to the same naming conventions and permissions checks as would be done on file creation. It will be visible in the filesystem, and will persist until unlinked.
On Windows, the local domain is implemented using a named pipe. The path must refer to an entry in \?pipe or \.pipe. Any characters are permitted, but the latter may do some processing of pipe names, such as resolving .. sequences. Despite appearances, the pipe name space is flat. Pipes will not persist, they are removed when the last reference to them is closed.
Synopsis
- data IPCClientConfig = IPCClientConfig {}
- data UVStream
- defaultIPCClientConfig :: IPCClientConfig
- initIPCClient :: IPCClientConfig -> Resource UVStream
- data IPCServerConfig = IPCServerConfig {}
- defaultIPCServerConfig :: IPCServerConfig
- startIPCServer :: HasCallStack => IPCServerConfig -> (UVStream -> IO ()) -> IO ()
- helloWorld :: UVStream -> IO ()
- echo :: UVStream -> IO ()
- initIPCStream :: HasCallStack => UVManager -> Resource UVStream
IPC Client
data IPCClientConfig Source #
A IPC client configuration
IPCClientConfig | |
|
Instances
A haskell data type wrap an uv_stream_t
inside
UVStream
DO NOT provide thread safety! Use UVStream
concurrently in multiple
threads will lead to undefined behavior.
defaultIPCClientConfig :: IPCClientConfig Source #
Default config, connect to "./ipc".
initIPCClient :: IPCClientConfig -> Resource UVStream Source #
init a IPC client Resource
, which open a new connect when used.
IPC Server
data IPCServerConfig Source #
A IPC server configuration
IPCServerConfig | |
|
Instances
defaultIPCServerConfig :: IPCServerConfig Source #
A default hello world server on ./ipc
Test it with main = startIPCServer defaultIPCServerConfig
:: HasCallStack | |
=> IPCServerConfig | |
-> (UVStream -> IO ()) | worker which get an accepted IPC stream, run in a seperated haskell thread, will be closed upon exception or worker finishes. |
-> IO () |
Start a server
Fork new worker thread upon a new connection.
For test
Internal helper
initIPCStream :: HasCallStack => UVManager -> Resource UVStream Source #