From c0f55440ba5e569e451bdc552d68d343c9f442bf Mon Sep 17 00:00:00 2001 From: fantasticbin Date: Sun, 14 Sep 2025 18:26:06 +0800 Subject: [PATCH] Zinx-V0.10 --- zinx/utils/config.go | 2 +- zinx/znet/connection.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/zinx/utils/config.go b/zinx/utils/config.go index 48417f3..0a83c90 100644 --- a/zinx/utils/config.go +++ b/zinx/utils/config.go @@ -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, diff --git a/zinx/znet/connection.go b/zinx/znet/connection.go index 71062bf..84b84f6 100644 --- a/zinx/znet/connection.go +++ b/zinx/znet/connection.go @@ -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 +}