1 Star 0 Fork 0

micro-tools/wf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gproc_comm_send.go 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
545403892 提交于 2023-09-27 22:16 +08:00 . 升级go-ole
package gproc
import (
"errors"
"gitee.com/micro-tools/wf/internal/json"
"gitee.com/micro-tools/wf/net/gtcp"
"io"
)
// Send sends data to specified process of given pid.
func Send(pid int, data []byte, group ...string) error {
msg := MsgRequest{
SendPid: Pid(),
RecvPid: pid,
Group: gPROC_COMM_DEFAULT_GRUOP_NAME,
Data: data,
}
if len(group) > 0 {
msg.Group = group[0]
}
msgBytes, err := json.Marshal(msg)
if err != nil {
return err
}
var conn *gtcp.PoolConn
conn, err = getConnByPid(pid)
if err != nil {
return err
}
defer conn.Close()
// Do the sending.
var result []byte
result, err = conn.SendRecvPkg(msgBytes, gtcp.PkgOption{
Retry: gtcp.Retry{
Count: 3,
},
})
if len(result) > 0 {
response := new(MsgResponse)
err = json.UnmarshalUseNumber(result, response)
if err == nil {
if response.Code != 1 {
err = errors.New(response.Message)
}
}
}
// EOF is not really an error.
if err == io.EOF {
err = nil
}
return err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/micro-tools/wf.git
git@gitee.com:micro-tools/wf.git
micro-tools
wf
wf
v1.0.2

搜索帮助