Fixed message buffer timeout

This commit is contained in:
Andrey Petrov 2016-07-24 16:16:12 -04:00
parent 3ba0c59341
commit 50d2be3a88
4 changed files with 8 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import (
)
const messageBuffer = 5
const messageTimeout = 5 * time.Second
const reHighlight = `\b(%s)\b`
var ErrUserClosed = errors.New("user closed")
@ -152,8 +153,8 @@ func (u *User) Send(m Message) error {
case u.msg <- m:
case <-u.done:
return ErrUserClosed
default:
logger.Printf("Msg buffer full, closing: %s", u.Name())
case <-time.After(messageTimeout):
logger.Printf("Message buffer full, closing: %s", u.Name())
u.Close()
return ErrUserClosed
}

View File

@ -85,6 +85,7 @@ func main() {
// Enable logging from submodules
chat.SetLogger(os.Stderr)
sshd.SetLogger(os.Stderr)
message.SetLogger(os.Stderr)
}
privateKeyPath := options.Identity

View File

@ -129,6 +129,8 @@ func (h *Host) Connect(term *sshd.Terminal) {
}
ratelimit := rateio.NewSimpleLimiter(3, time.Second*3)
logger.Debugf("Joined: %s", user.Name())
for {
line, err := term.ReadLine()
if err == io.EOF {
@ -175,6 +177,7 @@ func (h *Host) Connect(term *sshd.Terminal) {
logger.Errorf("Failed to leave: %s", err)
return
}
logger.Debugf("Leaving: %s", user.Name())
}
// Serve our chat room onto the listener

View File

@ -78,6 +78,7 @@ func NewTerminal(conn *ssh.ServerConn, ch ssh.NewChannel) (*Terminal, error) {
go func() {
for range time.Tick(keepaliveInterval) {
// TODO: Could break out earlier with a select if we want, rather than waiting for an error.
_, err := channel.SendRequest(keepaliveRequest, true, nil)
if err != nil {
// Connection is gone