channel

package
v2.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

README

Multi process IPC communication implemented in Go

introduction

based net socket & unix domain socket

Communication - Channel Selection

OS Version version IPC
windows < 10.17063 net socket
windows >= 10.17063 unix
linux all unix
macosx all unix

Documentation

Index

Constants

View Source
const (
	MemoryNetwork = "unix"
)

Variables

View Source
var IPCNetSocketPortKey = "--energy-ipc-net-socket-port"

IPCNetSocketPortKey IPC 监听端口号的Key名, 在初始化之前该值可被改变

Functions

func IsUseNetIPC added in v2.3.5

func IsUseNetIPC() bool

MacOS, Linux, Windows10 && Build >= 17063 时使用 unix socket Windows10 以下 && Windows10 Build < 17063 时使用 net socket

func MemoryAddress

func MemoryAddress() string

func Port

func Port() int

Port 获取并返回未使用的net socket端口

func SetPort

func SetPort(v int)

SetPort 设置 net socket 端口号, 如参数 "v" 非指定范围内端口则获取随机未使用端口号

v 1024 ~ 65535

func UseNetIPCChannel

func UseNetIPCChannel() bool

Types

type IBrowserChannel

type IBrowserChannel interface {
	Channel(channelId string) IChannel
	ChannelIds() (result []int64)
	Send(channelId string, data []byte)
	Handler(handler IPCCallback)
	Close()
}

func NewBrowser

func NewBrowser(addresses ...string) IBrowserChannel

NewBrowser Create main(browser) process channel

type IChannel

type IChannel interface {
	IsConnect() bool
	Close()
	// contains filtered or unexported methods
}

IChannel 通道链接

type IIPCContext

type IIPCContext interface {
	Connect() net.Conn        // IPC 通道链接
	ChannelId() string        // 返回 发送通道ID
	ToChannelId() string      // 返回 接收发送通道ID
	ChannelType() ChannelType // 返回 当前通道类型
	ProcessId() CefProcessId  // 返回 通道消息来源
	Message() IMessage        // 消息
	Free()                    //
}

IIPCContext IPC通信回调上下文

type IMessage

type IMessage interface {
	Type() mt        // 消息类型
	Length() int32   // 数据长度
	Data() []byte    // 数据
	JSON() json.JSON // 转为 JSON 对象并返回
	// contains filtered or unexported methods
}

IMessage 消息内容接口

type IPCCallback

type IPCCallback func(context IIPCContext)

IPCCallback 回调

type IPCContext

type IPCContext struct {
	// contains filtered or unexported fields
}

IPCContext IPC 上下文

func (*IPCContext) ChannelId

func (m *IPCContext) ChannelId() string

ChannelId 返回发送通道ID

func (*IPCContext) ChannelType

func (m *IPCContext) ChannelType() ChannelType

ChannelType 返回当前通道类型

func (*IPCContext) Connect

func (m *IPCContext) Connect() net.Conn

Connect 返回当前通道链接

func (*IPCContext) Free

func (m *IPCContext) Free()

Free 释放消息内存空间

func (*IPCContext) Message

func (m *IPCContext) Message() IMessage

Message 返回消息内容

func (*IPCContext) ProcessId

func (m *IPCContext) ProcessId() CefProcessId

func (*IPCContext) ToChannelId

func (m *IPCContext) ToChannelId() string

ToChannelId 返回接收通道ID

type IRenderChannel

type IRenderChannel interface {
	Channel() IChannel
	Send(data []byte)
	SendToChannel(toChannelId string, data []byte)
	UpdateChannelId(toChannelId string)
	Handler(handler IPCCallback)
	Close()
}

func NewRender

func NewRender(channelId string, addresses ...string) IRenderChannel

NewRender Create the renderer process channel

param: channelId Unique channel ID identifier

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL