Start starts the connection and makes the current connection work. (启动连接,让当前连接开始工作)
()
| 294 | // Start starts the connection and makes the current connection work. |
| 295 | // (启动连接,让当前连接开始工作) |
| 296 | func (c *Connection) Start() { |
| 297 | defer func() { |
| 298 | if err := recover(); err != nil { |
| 299 | zlog.Ins().ErrorF("Connection Start() error: %v", err) |
| 300 | } |
| 301 | }() |
| 302 | c.ctx, c.cancel = context.WithCancel(context.Background()) |
| 303 | |
| 304 | // Execute the hook method for processing business logic when creating a connection |
| 305 | // (按照用户传递进来的创建连接时需要处理的业务,执行钩子方法) |
| 306 | c.callOnConnStart() |
| 307 | |
| 308 | // Start heartbeating detection |
| 309 | if c.hc != nil { |
| 310 | c.hc.Start() |
| 311 | c.updateActivity() |
| 312 | } |
| 313 | |
| 314 | // 占用workerid |
| 315 | c.workerID = useWorker(c) |
| 316 | |
| 317 | // Start the Goroutine for reading data from the client |
| 318 | // (开启用户从客户端读取数据流程的Goroutine) |
| 319 | go c.StartReader() |
| 320 | |
| 321 | select { |
| 322 | case <-c.ctx.Done(): |
| 323 | c.finalizer() |
| 324 | |
| 325 | // 归还workerid |
| 326 | freeWorker(c) |
| 327 | return |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | // Stop stops the connection and ends the current connection state. |
| 332 | // (停止连接,结束当前连接状态) |
nothing calls this directly
no test coverage detected