本文整理汇总了Golang中push-server/protocol.Message.PushType方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.PushType方法的具体用法?Golang Message.PushType怎么用?Golang Message.PushType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类push-server/protocol.Message
的用法示例。
在下文中一共展示了Message.PushType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Save
func (this *CacheComponent) Save(msg protocol.Message) error {
this.CacheLock.Lock()
defer this.CacheLock.Unlock()
if this.Cache == nil {
this.Cache = make(map[string]CacheDev, 0)
}
if _, ok := this.Cache[msg.DestUuid]; !ok {
val := CacheDev{
MDev: make(map[uint32]*CacheList, 0),
}
this.Cache[msg.DestUuid] = val
}
if _, ok := this.Cache[msg.DestUuid].MDev[msg.DeviceId]; !ok {
val := &CacheList{
List: list.New(),
Total: 0,
}
this.Cache[msg.DestUuid].MDev[msg.DeviceId] = val
}
this.Cache[msg.DestUuid].MDev[msg.DeviceId].Total++
id := this.Cache[msg.DestUuid].MDev[msg.DeviceId].Total
msg.DataLen = 4 + msg.DataLen
buf := make([]byte, msg.DataLen)
binary.BigEndian.PutUint32(buf[0:4], id)
if len(msg.Data) > 0 {
copy(buf[4:msg.DataLen], msg.Data)
}
msg.Data = buf
msg.MsgType = protocol.MT_PUSH_WITH_RESPONSE
msg.PushType = protocol.PT_PUSHSERVER
msg.Number &= HEAD_RESET
e := this.Cache[msg.DestUuid].MDev[msg.DeviceId].List.PushBack(CacheEntry{msg, id})
if e == nil {
err := errors.New("CacheComponent.Save() Error: can not save msg to list")
fmt.Println(err.Error())
return err
}
return nil
}
示例2: handleKeepAlive
func (this *DispatcherComponent) handleKeepAlive(msg *protocol.Message) error {
if msg == nil {
err := errors.New("DispatcherComponent.handleKeepAlive() Error: invalid argument")
fmt.Println(err.Error())
return err
}
buffPool := buffpool.GetBuffPool()
err := buffPool.UpdateClientStatus(msg.Number, msg.UserUuid, msg.DeviceId, msg.Token, true)
if err != nil {
err = errors.New("DispatcherComponent.handleKeepAlive() Error: can not update client's connections status" + err.Error())
fmt.Println(err.Error())
return err
}
msg.PushType = protocol.PT_PUSHSERVER
msg.UserUuid, msg.DestUuid = msg.DestUuid, msg.UserUuid
GetDispatcherOutComponent().EPushBack(msg, false)
return nil
}