mirror of
https://gitee.com/johng/gf.git
synced 2024-12-03 04:37:49 +08:00
improving gproc
This commit is contained in:
parent
c5aa493d24
commit
e695983d4d
1
TODO.MD
1
TODO.MD
@ -50,7 +50,6 @@
|
||||
1. grpool增加支持阻塞添加任务接口;
|
||||
|
||||
|
||||
|
||||
# DONE
|
||||
1. gconv完善针对不同类型的判断,例如:尽量减少sprintf("%v", xxx)来执行string类型的转换;
|
||||
2. ghttp.Server请求执行中增加服务退出的方法,不再执行后续操作;
|
||||
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user