Documentation
¶
Overview ¶
Package tcpconn micserver 中的 TCP 连接管理,默认情况下,跨 App 的 Module 使用的便是 TCP 进行消息 通信,常用的客户端连接的协议也是 TCP 协议。
Index ¶
- Constants
- Variables
- type TCPConn
- func (tcpConn *TCPConn) GetMsgCodec() msg.IMsgCodec
- func (tcpConn *TCPConn) GetRecvMessageChannel() chan *msg.MessageBinary
- func (tcpConn *TCPConn) HookProtocal(p baseio.Protocal)
- func (tcpConn *TCPConn) Init(conn net.Conn, sendChanSize int, sendBufferSize int, recvChanSize int, ...) error
- func (tcpConn *TCPConn) IsAlive() bool
- func (tcpConn *TCPConn) Read(toData []byte) (int, error)
- func (tcpConn *TCPConn) RemoteAddr() string
- func (tcpConn *TCPConn) SendBytes(cmdid uint16, protodata []byte) error
- func (tcpConn *TCPConn) SendMessageBinary(msgbinary *msg.MessageBinary) error
- func (tcpConn *TCPConn) SetBanAutoResize(value bool)
- func (tcpConn *TCPConn) SetLogger(l *log.Logger)
- func (tcpConn *TCPConn) SetMsgCodec(codec msg.IMsgCodec)
- func (tcpConn *TCPConn) Shutdown() error
- func (tcpConn *TCPConn) StartRecv()
- func (tcpConn *TCPConn) Write(data []byte) (int, error)
Constants ¶
View Source
const ( // 未连接 TCPConnStateNone = 0 // 已连接 TCPConnStateLinked = 1 // 标记不可发送 TCPConnStateHold = 2 // 已关闭 TCPConnStateClosed = 3 )
TCPConn 的连接状态枚举
View Source
const (
MaxMsgPackSum = 200
)
消息合批时,合并的最大消息数量
Variables ¶
View Source
var ( ErrSendNilData = errors.New("send nil data") ErrCloseed = errors.New("conn has been closed") ErrBufferFull = errors.New("buffer full") )
tcp 连接的错误
Functions ¶
This section is empty.
Types ¶
type TCPConn ¶
type TCPConn struct {
// contains filtered or unexported fields
}
TCPConn TCP 连接
func (*TCPConn) GetMsgCodec ¶
GetMsgCodec 获取消息编解码器
func (*TCPConn) GetRecvMessageChannel ¶
func (tcpConn *TCPConn) GetRecvMessageChannel() chan *msg.MessageBinary
GetRecvMessageChannel 获取接收消息 chan
func (*TCPConn) HookProtocal ¶
HookProtocal 设置网络层协议
func (*TCPConn) Init ¶
func (tcpConn *TCPConn) Init(conn net.Conn, sendChanSize int, sendBufferSize int, recvChanSize int, recvBufferSize int) error
Init 初始化一个TCPConn对象
conn: net.Conn对象 sendChanSize: 发送等待队列中的消息缓冲区大小 sendBufferSize: 发送拼包发送缓冲区大小 recvChanSize: 接收等待队列中的消息缓冲区大小 recvBufferSize: 接收拼包发送缓冲区大小
返回:接收到的 messagebinary 的对象 chan
func (*TCPConn) SendMessageBinary ¶
func (tcpConn *TCPConn) SendMessageBinary( msgbinary *msg.MessageBinary) error
SendMessageBinary 发送 MsgBinary 消息
func (*TCPConn) SetBanAutoResize ¶
SetBanAutoResize 设置禁止缓冲区自动扩容
func (*TCPConn) SetMsgCodec ¶
SetMsgCodec 设置消息编解码器
Click to show internal directories.
Click to hide internal directories.