forked from Mirrors/gomuks
websocket/buffer: make size configurable
This commit is contained in:
parent
894fcb3fa0
commit
149114354a
2 changed files with 12 additions and 6 deletions
|
@ -48,7 +48,7 @@ func NewEventBuffer(maxSize int) *EventBuffer {
|
||||||
websocketClosers: make(map[uint64]WebsocketCloseFunc),
|
websocketClosers: make(map[uint64]WebsocketCloseFunc),
|
||||||
lastAckedID: make(map[uint64]int64),
|
lastAckedID: make(map[uint64]int64),
|
||||||
eventListeners: make(map[uint64]func(*hicli.JSONCommand)),
|
eventListeners: make(map[uint64]func(*hicli.JSONCommand)),
|
||||||
buf: make([]*hicli.JSONCommand, 0, maxSize*2),
|
buf: make([]*hicli.JSONCommand, 0, 32),
|
||||||
MaxSize: maxSize,
|
MaxSize: maxSize,
|
||||||
minID: -1,
|
minID: -1,
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ type WebConfig struct {
|
||||||
PasswordHash string `yaml:"password_hash"`
|
PasswordHash string `yaml:"password_hash"`
|
||||||
TokenKey string `yaml:"token_key"`
|
TokenKey string `yaml:"token_key"`
|
||||||
DebugEndpoints bool `yaml:"debug_endpoints"`
|
DebugEndpoints bool `yaml:"debug_endpoints"`
|
||||||
|
EventBufferSize int `yaml:"event_buffer_size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultFileWriter = zeroconfig.WriterConfig{
|
var defaultFileWriter = zeroconfig.WriterConfig{
|
||||||
|
@ -115,12 +116,17 @@ func (gmx *Gomuks) LoadConfig() error {
|
||||||
gmx.Config.Web.PasswordHash = string(hash)
|
gmx.Config.Web.PasswordHash = string(hash)
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
|
if gmx.Config.Web.EventBufferSize <= 0 {
|
||||||
|
gmx.Config.Web.EventBufferSize = 512
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
if changed {
|
if changed {
|
||||||
err = gmx.SaveConfig()
|
err = gmx.SaveConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to save config: %w", err)
|
return fmt.Errorf("failed to save config: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
gmx.EventBuffer = NewEventBuffer(gmx.Config.Web.EventBufferSize)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue