Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
3d2dd33d
energy
项目概览
energye
/
energy
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
energy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3d2dd33d
编写于
3月 19, 2023
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
upgrade-dev v2.3.15
上级
7f56f8a2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
42 addition
and
30 deletion
+42
-30
ipc/ipc-channel-browser.go
ipc/ipc-channel-browser.go
+5
-5
ipc/ipc-channel-render.go
ipc/ipc-channel-render.go
+2
-2
ipc/ipc-channel.go
ipc/ipc-channel.go
+35
-23
未找到文件。
ipc/ipc-channel-browser.go
浏览文件 @
3d2dd33d
...
...
@@ -110,7 +110,7 @@ func (m *browserChannel) Close() {
}
func
(
m
*
browserChannel
)
onConnect
(
context
IIPCContext
)
{
logger
.
Info
(
"IPC browser on connect channelId:"
,
context
.
ChannelId
())
logger
.
Info
(
"IPC browser on connect
key_
channelId:"
,
context
.
ChannelId
())
if
chn
:=
m
.
Channel
(
context
.
ChannelId
());
chn
!=
nil
{
chn
.
IPCType
=
m
.
ipcType
chn
.
Conn
=
context
.
Connect
()
...
...
@@ -123,7 +123,7 @@ func (m *browserChannel) onConnect(context IIPCContext) {
}
func
(
m
*
browserChannel
)
removeChannel
(
id
int64
)
{
logger
.
Debug
(
"IPC browser channel remove channelId:"
,
id
)
logger
.
Debug
(
"IPC browser channel remove
key_
channelId:"
,
id
)
m
.
channel
.
Delete
(
id
)
}
...
...
@@ -154,7 +154,7 @@ func (m *browserChannel) sendMessage(messageType mt, channelId int64, data []byt
channelId
=
id
}
if
chn
:=
m
.
Channel
(
channelId
);
chn
!=
nil
{
_
,
_
=
ipcWrite
(
messageType
,
data
,
chn
.
conn
())
_
,
_
=
ipcWrite
(
messageType
,
channelId
,
data
,
chn
.
conn
())
}
}
...
...
@@ -188,7 +188,7 @@ func (m *browserChannel) ipcReadHandler(conn net.Conn) {
logger
.
Error
(
"IPC Server Accept Recover:"
,
err
)
}
}()
var
id
int64
//render channel channelId
var
id
int64
//render channel
key_
channelId
defer
func
()
{
m
.
removeChannel
(
id
)
}()
...
...
@@ -199,7 +199,7 @@ func (m *browserChannel) ipcReadHandler(conn net.Conn) {
handler
:
func
(
context
IIPCContext
)
{
if
context
.
Message
()
.
Type
()
==
mt_connection
{
message
:=
json
.
NewJSONObject
(
context
.
Message
()
.
Data
())
id
=
int64
(
message
.
GetIntByKey
(
channelId
))
id
=
int64
(
message
.
GetIntByKey
(
key_
channelId
))
m
.
onConnect
(
context
)
}
else
{
if
m
.
handler
!=
nil
{
...
...
ipc/ipc-channel-render.go
浏览文件 @
3d2dd33d
...
...
@@ -62,7 +62,7 @@ func (m *ipcChannel) NewRenderChannel(channelId int64, memoryAddresses ...string
func
(
m
*
renderChannel
)
onConnection
()
{
message
:=
json
.
NewJSONObject
(
nil
)
message
.
Set
(
channelId
,
m
.
channelId
)
message
.
Set
(
key_
channelId
,
m
.
channelId
)
m
.
sendMessage
(
mt_connection
,
message
.
Bytes
())
message
.
Free
()
}
...
...
@@ -74,7 +74,7 @@ func (m *renderChannel) Send(data []byte) {
func
(
m
*
renderChannel
)
sendMessage
(
messageType
mt
,
data
[]
byte
)
{
m
.
mutex
.
Lock
()
defer
m
.
mutex
.
Unlock
()
_
,
_
=
ipcWrite
(
messageType
,
data
,
m
.
conn
())
_
,
_
=
ipcWrite
(
messageType
,
m
.
channelId
,
data
,
m
.
conn
())
}
func
(
m
*
renderChannel
)
Handler
(
handler
IPCCallback
)
{
...
...
ipc/ipc-channel.go
浏览文件 @
3d2dd33d
...
...
@@ -27,11 +27,12 @@ import (
)
var
(
protocolHeader
=
[]
byte
{
0x01
,
0x09
,
0x08
,
0x07
,
0x00
,
0x08
,
0x02
,
0x02
}
//协议头
protocolHeaderLength
=
int32
(
len
(
protocolHeader
))
//协议头长度
messageType
=
int32
(
1
)
//消息类型 int8
dataByteLength
=
int32
(
4
)
//数据长度 int32
headerLength
=
int
(
protocolHeaderLength
+
messageType
+
dataByteLength
)
//协议头长度
protocolHeader
=
[]
byte
{
0x01
,
0x09
,
0x08
,
0x07
,
0x00
,
0x08
,
0x02
,
0x02
}
//协议头
protocolHeaderLength
=
int32
(
len
(
protocolHeader
))
//协议头长度
messageTypeLength
=
int32
(
1
)
//消息类型 int8
channelIdLength
=
int32
(
8
)
//通道Id int64
dataByteLength
=
int32
(
4
)
//数据长度 int32
headerLength
=
int
(
protocolHeaderLength
+
messageTypeLength
+
channelIdLength
+
dataByteLength
)
//协议头长度
)
var
(
...
...
@@ -47,6 +48,7 @@ var (
mutex
:
sync
.
Mutex
{},
},
}
ipcWriteBuf
=
new
(
bytes
.
Buffer
)
)
//消息类型
...
...
@@ -58,7 +60,7 @@ const (
)
const
(
channelId
=
"
channelId"
key_channelId
=
"key_
channelId"
)
func
init
()
{
...
...
@@ -125,14 +127,14 @@ type messageCallback func(context IMessage)
// 进程间IPC通信回调上下文
type
IIPCContext
interface
{
Connect
()
net
.
Conn
//IPC 链接
ChannelId
()
int64
//render channel channelId
ChannelId
()
int64
//render channel
key_
channelId
Message
()
IMessage
//
Free
()
//
}
type
IMessage
interface
{
Type
()
mt
Length
()
int32
Length
()
u
int32
Data
()
[]
byte
JSON
()
json
.
JSON
clear
()
...
...
@@ -147,7 +149,7 @@ type ipcReadHandler struct {
type
ipcMessage
struct
{
t
mt
s
int32
s
u
int32
v
[]
byte
}
...
...
@@ -202,7 +204,7 @@ func (m *ipcMessage) Data() []byte {
return
m
.
v
}
func
(
m
*
ipcMessage
)
Length
()
int32
{
func
(
m
*
ipcMessage
)
Length
()
u
int32
{
return
m
.
s
}
...
...
@@ -215,7 +217,7 @@ func (m *ipcMessage) clear() {
m
.
s
=
0
}
func
ipcWrite
(
messageType
mt
,
data
[]
byte
,
conn
net
.
Conn
)
(
n
int
,
err
error
)
{
func
ipcWrite
(
messageType
mt
,
channelId
int64
,
data
[]
byte
,
conn
net
.
Conn
)
(
n
int
,
err
error
)
{
defer
func
()
{
data
=
nil
}()
...
...
@@ -225,14 +227,14 @@ func ipcWrite(messageType mt, data []byte, conn net.Conn) (n int, err error) {
var
(
dataByteLen
=
len
(
data
)
)
if
dataByteLen
>
math
.
Max
I
nt32
{
if
dataByteLen
>
math
.
Max
Ui
nt32
{
return
0
,
errors
.
New
(
"超出最大消息长度"
)
}
var
ipcWriteBuf
=
new
(
bytes
.
Buffer
)
binary
.
Write
(
ipcWriteBuf
,
binary
.
BigEndian
,
protocolHeader
)
//协议头
binary
.
Write
(
ipcWriteBuf
,
binary
.
BigEndian
,
int8
(
messageType
))
//消息类型
binary
.
Write
(
ipcWriteBuf
,
binary
.
BigEndian
,
int32
(
dataByteLen
))
//数据长度
binary
.
Write
(
ipcWriteBuf
,
binary
.
BigEndian
,
data
)
//数据
binary
.
Write
(
ipcWriteBuf
,
binary
.
BigEndian
,
protocolHeader
)
//协议头
binary
.
Write
(
ipcWriteBuf
,
binary
.
BigEndian
,
int8
(
messageType
))
//消息类型
binary
.
Write
(
ipcWriteBuf
,
binary
.
BigEndian
,
channelId
)
//通道Id
binary
.
Write
(
ipcWriteBuf
,
binary
.
BigEndian
,
u
int32
(
dataByteLen
))
//数据长度
binary
.
Write
(
ipcWriteBuf
,
binary
.
BigEndian
,
data
)
//数据
n
,
err
=
conn
.
Write
(
ipcWriteBuf
.
Bytes
())
ipcWriteBuf
.
Reset
()
return
n
,
err
...
...
@@ -271,18 +273,27 @@ func ipcRead(handler *ipcReadHandler) {
}
}
var
(
t
int8
//消息类型
dataLen
int32
//数据长度
low
,
high
int32
//
t
int8
//消息类型
channelId
int64
dataLen
uint32
//数据长度
low
,
high
int32
//
)
//消息类型
low
=
protocolHeaderLength
high
=
protocolHeaderLength
+
messageType
high
=
protocolHeaderLength
+
messageType
Length
err
=
binary
.
Read
(
bytes
.
NewReader
(
header
[
low
:
high
]),
binary
.
BigEndian
,
&
t
)
if
err
!=
nil
{
logger
.
Debug
(
"binary.Read.length: "
,
err
)
return
}
//通道ID
low
=
high
high
=
high
+
channelIdLength
err
=
binary
.
Read
(
bytes
.
NewReader
(
header
[
low
:
high
]),
binary
.
BigEndian
,
&
channelId
)
if
err
!=
nil
{
logger
.
Debug
(
"binary.Read.length: "
,
err
)
return
}
//数据长度
low
=
high
...
...
@@ -302,8 +313,9 @@ func ipcRead(handler *ipcReadHandler) {
return
}
handler
.
handler
(
&
IPCContext
{
ipcType
:
handler
.
ipcType
,
connect
:
handler
.
connect
,
channelId
:
channelId
,
ipcType
:
handler
.
ipcType
,
connect
:
handler
.
connect
,
message
:
&
ipcMessage
{
t
:
mt
(
t
),
s
:
dataLen
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录