Start starts the connection and makes it work. (Start 启动连接,让当前连接开始工作)
()
| 274 | // Start starts the connection and makes it work. |
| 275 | // (Start 启动连接,让当前连接开始工作) |
| 276 | func (c *WsConnection) Start() { |
| 277 | ctx := c.ctx |
| 278 | if ctx == nil { |
| 279 | ctx = context.Background() |
| 280 | } |
| 281 | c.ctx, c.cancel = context.WithCancel(ctx) |
| 282 | // Execute the hook method according to the business needs of creating the connection passed in by the user. |
| 283 | // (按照用户传递进来的创建连接时需要处理的业务,执行钩子方法) |
| 284 | c.callOnConnStart() |
| 285 | |
| 286 | // Start the heartbeat check |
| 287 | // (启动心跳检测) |
| 288 | if c.hc != nil { |
| 289 | c.hc.Start() |
| 290 | c.updateActivity() |
| 291 | } |
| 292 | |
| 293 | // 占用workerid |
| 294 | c.workerID = useWorker(c) |
| 295 | |
| 296 | // Start the Goroutine for users to read data from the client. |
| 297 | // (开启用户从客户端读取数据流程的Goroutine) |
| 298 | go c.StartReader() |
| 299 | |
| 300 | select { |
| 301 | case <-c.ctx.Done(): |
| 302 | c.finalizer() |
| 303 | |
| 304 | // 归还workerid |
| 305 | freeWorker(c) |
| 306 | return |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | // Stop stops the connection and ends its current state. |
| 311 | // (停止连接,结束当前连接状态) |
nothing calls this directly
no test coverage detected