完善服务器
This commit is contained in:
@@ -3,10 +3,43 @@ package grpc_server
|
||||
import (
|
||||
"common/log"
|
||||
"common/proto/gen/common"
|
||||
"common/proto/gen/grpc_pb"
|
||||
"context"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"scene/instance"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func (s *Server) SendMessage(ctx context.Context, req *common.Empty) (*common.Empty, error) {
|
||||
log.Infof("未实现函数")
|
||||
return nil, nil
|
||||
func (s *Server) Enter(ctx context.Context, req *grpc_pb.EnterReq) (*grpc_pb.EnterResp, error) {
|
||||
log.Infof("enter 触发 %v", req.SID)
|
||||
return nil, status.Errorf(codes.Unimplemented, "")
|
||||
}
|
||||
|
||||
func (s *Server) Action(server grpc_pb.Scene_ActionServer) error {
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.Errorf("Action panic: %v", err)
|
||||
}
|
||||
}()
|
||||
for {
|
||||
if args, err := server.Recv(); err != nil {
|
||||
return
|
||||
} else {
|
||||
if ins := instance.Mgr.GetByUniqueNo(args.UniqueNo); ins != nil {
|
||||
select {
|
||||
case ins.EventIn <- args:
|
||||
default:
|
||||
log.Warnf("instance event in full: %v, %v", ins.InstanceID, ins.UniqueNo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
wg.Wait()
|
||||
return server.SendAndClose(&common.Empty{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user