From e695983d4df6fb473a308629aea9347333366ba5 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 15 Jun 2019 16:07:36 +0800 Subject: [PATCH] improving gproc --- TODO.MD | 1 - g/container/gtree/gtree_avltree.go | 4 ++-- g/os/gproc/gproc_comm_send.go | 20 +++++++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/TODO.MD b/TODO.MD index 072b2c7d4..c56610e9c 100644 --- a/TODO.MD +++ b/TODO.MD @@ -50,7 +50,6 @@ 1. grpool增加支持阻塞添加任务接口; - # DONE 1. gconv完善针对不同类型的判断,例如:尽量减少sprintf("%v", xxx)来执行string类型的转换; 2. ghttp.Server请求执行中增加服务退出的方法,不再执行后续操作; diff --git a/g/container/gtree/gtree_avltree.go b/g/container/gtree/gtree_avltree.go index 7c67bc25f..18ff542b5 100644 --- a/g/container/gtree/gtree_avltree.go +++ b/g/container/gtree/gtree_avltree.go @@ -343,7 +343,7 @@ func (tree *AVLTree) Floor(key interface{}) (floor *AVLTreeNode, found bool) { // all nodes in the tree is smaller than the given node. // // Key should adhere to the comparator's type assertion, otherwise method panics. -func (tree *AVLTree) Ceiling(key interface{}) (floor *AVLTreeNode, found bool) { +func (tree *AVLTree) Ceiling(key interface{}) (ceiling *AVLTreeNode, found bool) { tree.mu.RLock() defer tree.mu.RUnlock() found = false @@ -354,7 +354,7 @@ func (tree *AVLTree) Ceiling(key interface{}) (floor *AVLTreeNode, found bool) { case c == 0: return n, true case c > 0: n = n.children[1] case c < 0: - floor, found = n, true + ceiling, found = n, true n = n.children[0] } } diff --git a/g/os/gproc/gproc_comm_send.go b/g/os/gproc/gproc_comm_send.go index bb7873200..c28453e74 100644 --- a/g/os/gproc/gproc_comm_send.go +++ b/g/os/gproc/gproc_comm_send.go @@ -26,21 +26,23 @@ const ( gPROC_COMM_DEAFULT_GRUOP_NAME = "" // 默认分组名称 ) +// 进程通信数据结构 +type gPkg struct { + SendPid int // 发送进程ID + RecvPid int // 接收进程ID + Group string // 分组名称 + Data []byte // 原始数据 + +} + // 向指定gproc进程发送数据. -// 数据格式:总长度(24bit)|发送进程PID(24bit)|接收进程PID(24bit)|分组长度(8bit)|分组名称(变长)|校验(32bit)|参数(变长) +// 数据格式:总长度(24bit)|发送进程PID(24bit)|接收进程PID(24bit)|分组长度(8bit)|分组名称(变长)|参数(变长) func Send(pid int, data []byte, group...string) error { groupName := gPROC_COMM_DEAFULT_GRUOP_NAME if len(group) > 0 { groupName = group[0] } - buffer := make([]byte, 0) - buffer = append(buffer, gbinary.EncodeByLength(3, len(groupName) + len(data) + 14)...) - buffer = append(buffer, gbinary.EncodeByLength(3, Pid())...) - buffer = append(buffer, gbinary.EncodeByLength(3, pid)...) - buffer = append(buffer, gbinary.EncodeByLength(1, len(groupName))...) - buffer = append(buffer, []byte(groupName)...) - buffer = append(buffer, gbinary.EncodeUint32(gtcp.Checksum(data))...) - buffer = append(buffer, data...) + // 执行发送流程 var err error var buf []byte