MCPcopy
hub / github.com/aceld/zinx / newWebsocketConn

Function newWebsocketConn

znet/ws_connection.go:119–152  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

117// (newServerConn :for Server, 创建一个Server服务端特性的连接的方法
118// Note: 名字由 NewConnection 更变)
119func 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服务端特性的连接的方法)

Callers 1

ListenWebsocketConnMethod · 0.85

Calls 13

NewFrameDecoderFunction · 0.92
ContextMethod · 0.65
ServerNameMethod · 0.65
LocalAddrMethod · 0.65
RemoteAddrMethod · 0.65
GetLengthFieldMethod · 0.65
GetPacketMethod · 0.65
GetOnConnStartMethod · 0.65
GetOnConnStopMethod · 0.65
GetMsgHandlerMethod · 0.65
GetConnMgrMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected