(data []byte, opts ...ziface.MsgSendOption)
| 365 | } |
| 366 | |
| 367 | func (c *KcpConnection) SendToQueue(data []byte, opts ...ziface.MsgSendOption) error { |
| 368 | c.msgLock.RLock() |
| 369 | defer c.msgLock.RUnlock() |
| 370 | |
| 371 | if c.msgBuffChan == nil { |
| 372 | c.msgBuffChan = make(chan []byte, zconf.GlobalObject.MaxMsgChanLen) |
| 373 | // Start a Goroutine to write data back to the client |
| 374 | // This method only reads data from the MsgBuffChan without allocating memory or starting a Goroutine |
| 375 | // (开启用于写回客户端数据流程的Goroutine |
| 376 | // 此方法只读取MsgBuffChan中的数据没调用SendBuffMsg可以分配内存和启用协程) |
| 377 | go c.StartWriter() |
| 378 | } |
| 379 | |
| 380 | opt := ziface.MsgSendOptionObj{ |
| 381 | Timeout: 5 * time.Millisecond, |
| 382 | } |
| 383 | |
| 384 | for _, o := range opts { |
| 385 | o(&opt) |
| 386 | } |
| 387 | |
| 388 | idleTimeout := time.NewTimer(opt.Timeout) |
| 389 | defer idleTimeout.Stop() |
| 390 | |
| 391 | if c.isClosed() { |
| 392 | return errors.New("Connection closed when send buff msg") |
| 393 | } |
| 394 | |
| 395 | if data == nil { |
| 396 | zlog.Ins().ErrorF("Pack data is nil") |
| 397 | return errors.New("Pack data is nil") |
| 398 | } |
| 399 | |
| 400 | // Send timeout |
| 401 | select { |
| 402 | case <-idleTimeout.C: |
| 403 | return errors.New("send buff msg timeout") |
| 404 | case c.msgBuffChan <- data: |
| 405 | return nil |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | // SendMsg directly sends Message data to the remote KCP client. |
| 410 | // (直接将Message数据发送数据给远程的KCP客户端) |
nothing calls this directly
no test coverage detected