Prevent terminal msg from being overwritten to later concurrent writes

This commit is contained in:
Andy Wang 2021-01-12 20:59:30 +00:00
parent 32494b8d86
commit 91106f3c49
No known key found for this signature in database
GPG Key ID: 181B49F9F38F3374
1 changed files with 6 additions and 8 deletions

View File

@ -73,7 +73,8 @@ type Session struct {
closed uint32
terminalMsg atomic.Value
terminalMsgSetter sync.Once
terminalMsg string
// the max size passed to Write calls before it splits it into multiple frames
// i.e. the max size a piece of data can fit into a Frame.Payload
@ -263,16 +264,13 @@ func (sesh *Session) recvDataFromRemote(data []byte) error {
}
func (sesh *Session) SetTerminalMsg(msg string) {
sesh.terminalMsg.Store(msg)
sesh.terminalMsgSetter.Do(func() {
sesh.terminalMsg = msg
})
}
func (sesh *Session) TerminalMsg() string {
msg := sesh.terminalMsg.Load()
if msg != nil {
return msg.(string)
} else {
return ""
}
return sesh.terminalMsg
}
func (sesh *Session) closeSession() error {