WsConnection is a module for handling the read and write operations of a WebSocket connection. (Websocket连接模块, 用于处理 Websocket 连接的读写业务 一个连接对应一个Connection)
| 24 | // WsConnection is a module for handling the read and write operations of a WebSocket connection. |
| 25 | // (Websocket连接模块, 用于处理 Websocket 连接的读写业务 一个连接对应一个Connection) |
| 26 | type WsConnection struct { |
| 27 | // conn is the current connection's WebSocket socket TCP socket. (当前连接的socket TCP套接字) |
| 28 | conn *websocket.Conn |
| 29 | |
| 30 | // connID is the current connection's ID, which can also be referred to as SessionID, and is globally unique. |
| 31 | // uint64 range: 018,446,744,073,709,551,615 |
| 32 | // This is the maximum number of connIDs that the theory supports per process. |
| 33 | // (当前连接的ID 也可以称作为SessionID,ID全局唯一 ,服务端Connection使用 |
| 34 | // uint64 取值范围:0 ~ 18,446,744,073,709,551,615 |
| 35 | // 这个是理论支持的进程connID的最大数量) |
| 36 | connID uint64 |
| 37 | |
| 38 | // connection id for string |
| 39 | // (字符串的连接id) |
| 40 | connIdStr string |
| 41 | |
| 42 | // The workerid responsible for handling the link |
| 43 | // 负责处理该连接的workerid |
| 44 | workerID uint32 |
| 45 | |
| 46 | // msgHandler is the message management module for MsgID and the corresponding message handling method. |
| 47 | // (消息管理MsgID和对应处理方法的消息管理模块) |
| 48 | msgHandler ziface.IMsgHandle |
| 49 | |
| 50 | // ctx and cancel are used to notify that the connection has exited/stopped. |
| 51 | // (告知该连接已经退出/停止的channel) |
| 52 | ctx context.Context |
| 53 | cancel context.CancelFunc |
| 54 | |
| 55 | // msgBuffChan is a buffered channel used for message communication between the read and write goroutines. |
| 56 | // (有缓冲管道,用于读、写两个goroutine之间的消息通信) |
| 57 | msgBuffChan chan []byte |
| 58 | |
| 59 | // msgLock is used for locking when users send and receive messages. |
| 60 | // (用户收发消息的Lock) |
| 61 | msgLock sync.Mutex |
| 62 | |
| 63 | // property is the connection attribute. (连接属性) |
| 64 | property map[string]interface{} |
| 65 | |
| 66 | // propertyLock protects the current property lock. (保护当前property的锁) |
| 67 | propertyLock sync.Mutex |
| 68 | |
| 69 | // isClosed is the current connection's closed state. (当前连接的关闭状态) |
| 70 | isClosed bool |
| 71 | |
| 72 | // connManager is the Connection Manager to which the current connection belongs. (当前连接是属于哪个Connection Manager的) |
| 73 | connManager ziface.IConnManager |
| 74 | |
| 75 | // onConnStart is the Hook function when the current connection is created. |
| 76 | // (当前连接创建时Hook函数) |
| 77 | onConnStart func(conn ziface.IConnection) |
| 78 | |
| 79 | // onConnStop is the Hook function when the current connection is disconnected. |
| 80 | // (当前连接断开时的Hook函数) |
| 81 | onConnStop func(conn ziface.IConnection) |
| 82 | |
| 83 | // packet is the data packet format. |
nothing calls this directly
no outgoing calls
no test coverage detected