Z-IO-0.6.1.0: Simple and high performance IO toolkit for Haskell
Copyright(c) Dong Han 2018
LicenseBSD
Maintainerwinterland1989@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Z.IO.Network.IPC

Description

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

IPC Client

data IPCClientConfig Source #

A IPC client configuration

Constructors

IPCClientConfig 

Fields

Instances

Instances details
Eq IPCClientConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

Ord IPCClientConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

Read IPCClientConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

Show IPCClientConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

Generic IPCClientConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

Associated Types

type Rep IPCClientConfig :: Type -> Type #

JSON IPCClientConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

Print IPCClientConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

type Rep IPCClientConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

type Rep IPCClientConfig = D1 ('MetaData "IPCClientConfig" "Z.IO.Network.IPC" "Z-IO-0.6.1.0-gzKEsYtajW4dyRTMbokGF" 'False) (C1 ('MetaCons "IPCClientConfig" 'PrefixI 'True) (S1 ('MetaSel ('Just "ipcClientName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe CBytes)) :*: S1 ('MetaSel ('Just "ipcTargetName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CBytes)))

data UVStream Source #

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.

Instances

Instances details
Show UVStream Source # 
Instance details

Defined in Z.IO.UV.UVStream

Print UVStream Source # 
Instance details

Defined in Z.IO.UV.UVStream

Methods

toUTF8BuilderP :: Int -> UVStream -> Builder () #

Output UVStream Source # 
Instance details

Defined in Z.IO.UV.UVStream

Methods

writeOutput :: UVStream -> Ptr Word8 -> Int -> IO () Source #

Input UVStream Source # 
Instance details

Defined in Z.IO.UV.UVStream

Methods

readInput :: UVStream -> Ptr Word8 -> Int -> IO Int Source #

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

Constructors

IPCServerConfig 

Fields

Instances

Instances details
Eq IPCServerConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

Ord IPCServerConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

Read IPCServerConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

Show IPCServerConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

Generic IPCServerConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

Associated Types

type Rep IPCServerConfig :: Type -> Type #

JSON IPCServerConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

Print IPCServerConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

type Rep IPCServerConfig Source # 
Instance details

Defined in Z.IO.Network.IPC

type Rep IPCServerConfig = D1 ('MetaData "IPCServerConfig" "Z.IO.Network.IPC" "Z-IO-0.6.1.0-gzKEsYtajW4dyRTMbokGF" 'False) (C1 ('MetaCons "IPCServerConfig" 'PrefixI 'True) (S1 ('MetaSel ('Just "ipcListenName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 CBytes) :*: S1 ('MetaSel ('Just "ipcListenBacklog") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

defaultIPCServerConfig :: IPCServerConfig Source #

A default hello world server on ./ipc

Test it with main = startIPCServer defaultIPCServerConfig

startIPCServer Source #

Arguments

:: 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

helloWorld :: UVStream -> IO () Source #

Write "hello world" to a UVStream.

echo :: UVStream -> IO () Source #

Echo whatever received bytes.

Internal helper