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

Method SendMsg

znet/connection.go:447–466  ·  view source on GitHub ↗

SendMsg directly sends Message data to the remote TCP client. (直接将Message数据发送数据给远程的TCP客户端)

(msgID uint32, data []byte)

Source from the content-addressed store, hash-verified

445// SendMsg directly sends Message data to the remote TCP client.
446// (直接将Message数据发送数据给远程的TCP客户端)
447func (c *Connection) SendMsg(msgID uint32, data []byte) error {
448
449 if c.isClosed() == true {
450 return errors.New("connection closed when send msg")
451 }
452 // Pack data and send it
453 msg, err := c.packet.Pack(zpack.NewMsgPackage(msgID, data))
454 if err != nil {
455 zlog.Ins().ErrorF("Pack error msg ID = %d", msgID)
456 return errors.New("Pack error msg ")
457 }
458
459 err = c.Send(msg)
460 if err != nil {
461 zlog.Ins().ErrorF("SendMsg err msg ID = %d, data = %+v, err = %+v", msgID, string(msg), err)
462 return err
463 }
464
465 return nil
466}
467
468func (c *Connection) SendBuffMsg(msgID uint32, data []byte, opts ...ziface.MsgSendOption) error {
469 msg, err := c.packet.Pack(zpack.NewMsgPackage(msgID, data))

Callers

nothing calls this directly

Calls 6

isClosedMethod · 0.95
SendMethod · 0.95
NewMsgPackageFunction · 0.92
InsFunction · 0.92
PackMethod · 0.65
ErrorFMethod · 0.65

Tested by

no test coverage detected