Files
chain33-im/comet/operation.go
2022-03-17 15:55:27 +08:00

45 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package comet
import (
"context"
"strconv"
"gitlab.33.cn/chat/im/api/comet/grpc"
"gitlab.33.cn/chat/im/dtask"
)
// Operate operate.
func (s *Comet) Operate(ctx context.Context, p *grpc.Proto, ch *Channel, tsk *dtask.Task) error {
switch p.Op {
case int32(grpc.Op_SendMsg):
//标明Ack的消息序列
p.Ack = p.Seq
err := s.Receive(ctx, ch.Key, p)
if err != nil {
//下层业务调用失败返回error的话会直接断开连接
return err
}
//p.Op = int32(grpc.Op_SendMsgReply)
case int32(grpc.Op_ReceiveMsgReply):
//从task中删除某一条
if j := tsk.Get(strconv.FormatInt(int64(p.Ack), 10)); j != nil {
j.Cancel()
}
err := s.Receive(ctx, ch.Key, p)
if err != nil {
//下层业务调用失败返回error的话会直接断开连接
return err
}
case int32(grpc.Op_SyncMsgReq):
err := s.Receive(ctx, ch.Key, p)
if err != nil {
//下层业务调用失败返回error的话会直接断开连接
return err
}
p.Op = int32(grpc.Op_SyncMsgReply)
default:
return s.Receive(ctx, ch.Key, p)
}
return nil
}