MCPcopy
hub / github.com/aceld/zinx / Handle

Method Handle

examples/zinx_dynamic_bind/server/server.go:27–47  ·  view source on GitHub ↗

模拟阻塞操作

(request ziface.IRequest)

Source from the content-addressed store, hash-verified

25
26// 模拟阻塞操作
27func (r *blockRouter) Handle(request ziface.IRequest) {
28 //read client data
29 zlog.Infof("recv from client:%s, msgId=%d, data=%s\n", request.GetConnection().RemoteAddr(), request.GetMsgID(), string(request.GetData()))
30
31 // 第一次处理时,模拟任务阻塞操作, Hash 模式下,后面的连接的任务得不到处理
32 // DynamicBind 模式下,看后面的连接的任务会得到即使处理,不会因为前面连接的任务阻塞而得不到处理
33 // 这里只模拟一次阻塞操作。
34 if atomic.CompareAndSwapInt32(&Block, 1, 0) {
35 zlog.Infof("blockRouter handle start, msgId=%d, remote:%v\n", request.GetMsgID(), request.GetConnection().RemoteAddr())
36 time.Sleep(time.Second * 10)
37 //阻塞操作结束
38 zlog.Infof("blockRouter handle end, msgId=%d, remote:%v\n", request.GetMsgID(), request.GetConnection().RemoteAddr())
39 }
40
41 err := request.GetConnection().SendMsg(2, []byte("pong from server"))
42 if err != nil {
43 zlog.Error(err)
44 return
45 }
46 zlog.Infof("send pong over, client:%s\n", request.GetConnection().RemoteAddr())
47}
48
49func main() {
50 s := znet.NewServer()

Callers

nothing calls this directly

Calls 7

InfofFunction · 0.92
ErrorFunction · 0.92
RemoteAddrMethod · 0.65
GetConnectionMethod · 0.65
GetMsgIDMethod · 0.65
GetDataMethod · 0.65
SendMsgMethod · 0.65

Tested by

no test coverage detected