mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-13 15:47:17 +03:00
Fixed message buffer timeout
This commit is contained in:
parent
3ba0c59341
commit
50d2be3a88
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
3
host.go
3
host.go
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user