newServerConn: for Server, a method to create a connection with Server characteristics Note: The name has been changed from NewConnection (newServerConn :for Server, 创建一个Server服务端特性的连接的方法 Note: 名字由 NewConnection 更变)
(server ziface.IServer, conn *websocket.Conn, connID uint64, r *http.Request)
| 117 | // (newServerConn :for Server, 创建一个Server服务端特性的连接的方法 |
| 118 | // Note: 名字由 NewConnection 更变) |
| 119 | func newWebsocketConn(server ziface.IServer, conn *websocket.Conn, connID uint64, r *http.Request) ziface.IConnection { |
| 120 | // Initialize Conn properties (初始化Conn属性) |
| 121 | c := &WsConnection{ |
| 122 | ctx: context.WithValue(context.Background(), WsConnectionHttpReqCtxKey{}, r.Context()), // websocketAuth可以在上下文中传递特殊的参数或信息;比如鉴权后,设置一些用户信息或房间id |
| 123 | conn: conn, |
| 124 | connID: connID, |
| 125 | connIdStr: strconv.FormatUint(connID, 10), |
| 126 | isClosed: false, |
| 127 | msgBuffChan: nil, |
| 128 | property: nil, |
| 129 | name: server.ServerName(), |
| 130 | localAddr: conn.LocalAddr().String(), |
| 131 | remoteAddr: conn.RemoteAddr().String(), |
| 132 | } |
| 133 | |
| 134 | lengthField := server.GetLengthField() |
| 135 | if lengthField != nil { |
| 136 | c.frameDecoder = zinterceptor.NewFrameDecoder(*lengthField) |
| 137 | } |
| 138 | |
| 139 | // Inherited attributes from server (从server继承过来的属性) |
| 140 | c.packet = server.GetPacket() |
| 141 | c.onConnStart = server.GetOnConnStart() |
| 142 | c.onConnStop = server.GetOnConnStop() |
| 143 | c.msgHandler = server.GetMsgHandler() |
| 144 | |
| 145 | // Bind the current Connection to the Server's ConnManager (将当前的Connection与Server的ConnManager绑定) |
| 146 | c.connManager = server.GetConnMgr() |
| 147 | |
| 148 | // Add the newly created Conn to the connection management (将新创建的Conn添加到连接管理中) |
| 149 | server.GetConnMgr().Add(c) |
| 150 | |
| 151 | return c |
| 152 | } |
| 153 | |
| 154 | // newClientConn :for Client, creates a connection with Client-side features |
| 155 | // (newClientConn :for Client, 创建一个Client服务端特性的连接的方法) |
no test coverage detected