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