Zinx-V0.10
This commit is contained in:
parent
ee55a8afa3
commit
c0f55440ba
@ -60,7 +60,7 @@ func init() {
|
||||
// 初始化全局配置,并设置默认值
|
||||
ConfigInstance = &Config{
|
||||
Name: "ZinxServerApp",
|
||||
Version: "V0.9",
|
||||
Version: "V0.10",
|
||||
Host: "0.0.0.0",
|
||||
TcpPort: 7777,
|
||||
MaxConn: 12000,
|
||||
|
@ -1,6 +1,7 @@
|
||||
package znet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go-study/zinx/utils"
|
||||
"go-study/zinx/ziface"
|
||||
@ -26,11 +27,16 @@ type Connection struct {
|
||||
msgChan chan []byte
|
||||
// 有缓冲管道,用于读、写两个 Goroutine 之间的消息通信
|
||||
msgBuffChan chan []byte
|
||||
|
||||
// 当前连接的上下文,用于连接属性传递和生命周期管理
|
||||
// Zinx 源代码中并没有使用该字段,而是通过一个 map[string]interface{} 属性集合来实现的
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
// NewConnection 创建连接的方法
|
||||
func NewConnection(server ziface.IServer, conn *net.TCPConn, connID uint32, msgHandler ziface.IMsgHandle) *Connection {
|
||||
c := &Connection{
|
||||
ctx: context.Background(),
|
||||
TcpServer: server,
|
||||
Conn: conn,
|
||||
ConnID: connID,
|
||||
@ -212,6 +218,7 @@ func (c *Connection) SendMsg(msgID uint32, data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendBuffMsg 发送有缓冲数据,将数据发送给远程的客户端
|
||||
func (c *Connection) SendBuffMsg(msgID uint32, data []byte) error {
|
||||
if c.IsClosed {
|
||||
return fmt.Errorf("connection closed when send buff msg")
|
||||
@ -230,3 +237,8 @@ func (c *Connection) SendBuffMsg(msgID uint32, data []byte) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetContext 获取当前连接的上下文
|
||||
func (c *Connection) GetContext() context.Context {
|
||||
return c.ctx
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user