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

Function newServerWithConfig

znet/server.go:129–178  ·  view source on GitHub ↗

newServerWithConfig creates a server handle based on config (根据config创建一个服务器句柄)

(config *zconf.Config, ipVersion string, opts ...Option)

Source from the content-addressed store, hash-verified

127// newServerWithConfig creates a server handle based on config
128// (根据config创建一个服务器句柄)
129func newServerWithConfig(config *zconf.Config, ipVersion string, opts ...Option) ziface.IServer {
130 logo.PrintLogo()
131
132 s := &Server{
133 Name: config.Name,
134 IPVersion: ipVersion,
135 IP: config.Host,
136 Port: config.TCPPort,
137 WsPort: config.WsPort,
138 WsPath: config.WsPath,
139 KcpPort: config.KcpPort,
140 msgHandler: newMsgHandle(),
141 RouterSlicesMode: config.RouterSlicesMode,
142 RequestPoolMode: config.RequestPoolMode,
143 ConnMgr: newConnManager(),
144 exitChan: nil,
145 // Default to using Zinx's TLV data pack format
146 // (默认使用zinx的TLV封包方式)
147 packet: zpack.Factory().NewPack(ziface.ZinxDataPack),
148 decoder: zdecoder.NewTLVDecoder(), // Default to using TLV decode (默认使用TLV的解码方式)
149 upgrader: &websocket.Upgrader{
150 ReadBufferSize: int(config.IOReadBuffSize),
151 CheckOrigin: func(r *http.Request) bool {
152 return true
153 },
154 },
155 kcpConfig: &KcpConfig{
156 KcpACKNoDelay: config.KcpACKNoDelay,
157 KcpStreamMode: config.KcpStreamMode,
158 KcpNoDelay: config.KcpNoDelay,
159 KcpInterval: config.KcpInterval,
160 KcpResend: config.KcpResend,
161 KcpNc: config.KcpNc,
162 KcpSendWindow: config.KcpSendWindow,
163 KcpRecvWindow: config.KcpRecvWindow,
164 KcpFecDataShards: config.KcpFecDataShards,
165 KcpFecParityShards: config.KcpFecParityShards,
166 },
167 }
168
169 for _, opt := range opts {
170 opt(s)
171 }
172
173 // Display current configuration information
174 // (提示当前配置信息)
175 config.Show()
176
177 return s
178}
179
180// NewServer creates a server handle
181// (创建一个服务器句柄)

Callers 4

NewServerFunction · 0.85
NewUserConfServerFunction · 0.85

Calls 7

PrintLogoFunction · 0.92
FactoryFunction · 0.92
NewTLVDecoderFunction · 0.92
newMsgHandleFunction · 0.85
newConnManagerFunction · 0.85
NewPackMethod · 0.80
ShowMethod · 0.80

Tested by

no test coverage detected