mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-09 11:52:37 +03:00
Fixing another crash bug?
This commit is contained in:
parent
8bba2e3917
commit
3025e59935
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
@ -71,6 +72,8 @@ type Client struct {
|
|||||||
lastTX time.Time
|
lastTX time.Time
|
||||||
beepMe bool
|
beepMe bool
|
||||||
colorMe bool
|
colorMe bool
|
||||||
|
closed bool
|
||||||
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient constructs a new client
|
// NewClient constructs a new client
|
||||||
@ -114,7 +117,7 @@ func (c *Client) WriteLines(msg []string) {
|
|||||||
|
|
||||||
// Send sends the given message
|
// Send sends the given message
|
||||||
func (c *Client) Send(msg string) {
|
func (c *Client) Send(msg string) {
|
||||||
if len(msg) > MaxMsgLength {
|
if len(msg) > MaxMsgLength || c.closed {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
@ -193,8 +196,9 @@ func (c *Client) handleShell(channel ssh.Channel) {
|
|||||||
go func() {
|
go func() {
|
||||||
// Block until done, then remove.
|
// Block until done, then remove.
|
||||||
c.Conn.Wait()
|
c.Conn.Wait()
|
||||||
close(c.Msg)
|
c.closed = true
|
||||||
c.Server.Remove(c)
|
c.Server.Remove(c)
|
||||||
|
close(c.Msg)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user