|
|
@ -68,6 +68,7 @@ type WsServer struct {
|
|
|
|
onlineUserNum atomic.Int64
|
|
|
|
onlineUserNum atomic.Int64
|
|
|
|
onlineUserConnNum atomic.Int64
|
|
|
|
onlineUserConnNum atomic.Int64
|
|
|
|
handshakeTimeout time.Duration
|
|
|
|
handshakeTimeout time.Duration
|
|
|
|
|
|
|
|
writeBufferSize int
|
|
|
|
validate *validator.Validate
|
|
|
|
validate *validator.Validate
|
|
|
|
cache cache.MsgModel
|
|
|
|
cache cache.MsgModel
|
|
|
|
userClient *rpcclient.UserRpcClient
|
|
|
|
userClient *rpcclient.UserRpcClient
|
|
|
@ -137,6 +138,7 @@ func NewWsServer(opts ...Option) (*WsServer, error) {
|
|
|
|
return &WsServer{
|
|
|
|
return &WsServer{
|
|
|
|
port: config.port,
|
|
|
|
port: config.port,
|
|
|
|
wsMaxConnNum: config.maxConnNum,
|
|
|
|
wsMaxConnNum: config.maxConnNum,
|
|
|
|
|
|
|
|
writeBufferSize: config.writeBufferSize,
|
|
|
|
handshakeTimeout: config.handshakeTimeout,
|
|
|
|
handshakeTimeout: config.handshakeTimeout,
|
|
|
|
clientPool: sync.Pool{
|
|
|
|
clientPool: sync.Pool{
|
|
|
|
New: func() interface{} {
|
|
|
|
New: func() interface{} {
|
|
|
@ -430,7 +432,8 @@ func (ws *WsServer) wsHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
httpError(connContext, errs.ErrTokenNotExist.Wrap())
|
|
|
|
httpError(connContext, errs.ErrTokenNotExist.Wrap())
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wsLongConn := newGWebSocket(WebSocket, ws.handshakeTimeout)
|
|
|
|
|
|
|
|
|
|
|
|
wsLongConn := newGWebSocket(WebSocket, ws.handshakeTimeout, ws.writeBufferSize)
|
|
|
|
err = wsLongConn.GenerateLongConn(w, r)
|
|
|
|
err = wsLongConn.GenerateLongConn(w, r)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
httpError(connContext, err)
|
|
|
|
httpError(connContext, err)
|
|
|
|