mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-14 08:07:16 +03:00
Fix buffer fill stuck.;
This commit is contained in:
parent
3f20f1795c
commit
ed74e12b6d
@ -55,3 +55,5 @@ things up with `make run`.
|
|||||||
* [ ] Lots of refactoring
|
* [ ] Lots of refactoring
|
||||||
* [ ] Pull out the chat-related stuff into isolation from the ssh serving
|
* [ ] Pull out the chat-related stuff into isolation from the ssh serving
|
||||||
stuff
|
stuff
|
||||||
|
|
||||||
|
* Fix hanging on collision connect
|
||||||
|
17
server.go
17
server.go
@ -74,20 +74,17 @@ func (s *Server) Broadcast(msg string, except *Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Add(client *Client) {
|
func (s *Server) Add(client *Client) {
|
||||||
for _, msg := range s.history.Get(10) {
|
go func() {
|
||||||
if msg == "" {
|
client.WriteLines(s.history.Get(10))
|
||||||
continue
|
client.Write(fmt.Sprintf("-> Welcome to ssh-chat. Enter /help for more.\r\n"))
|
||||||
}
|
}()
|
||||||
client.Msg <- msg
|
|
||||||
}
|
|
||||||
client.Msg <- fmt.Sprintf("-> Welcome to ssh-chat. Enter /help for more.\r\n")
|
|
||||||
|
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
s.count++
|
s.count++
|
||||||
|
|
||||||
newName, err := s.proposeName(client.Name)
|
newName, err := s.proposeName(client.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.Msg <- fmt.Sprintf("-> Your name '%s' is not avaialble, renamed to '%s'. Use /nick <name> to change it.\r\n", client.Name, newName)
|
client.Msg <- fmt.Sprintf("-> Your name '%s' is not available, renamed to '%s'. Use /nick <name> to change it.\r\n", client.Name, newName)
|
||||||
}
|
}
|
||||||
|
|
||||||
client.Name = newName
|
client.Name = newName
|
||||||
@ -196,15 +193,13 @@ func (s *Server) Start(laddr string) error {
|
|||||||
go ssh.DiscardRequests(requests)
|
go ssh.DiscardRequests(requests)
|
||||||
|
|
||||||
client := NewClient(s, sshConn)
|
client := NewClient(s, sshConn)
|
||||||
|
client.handleChannels(channels)
|
||||||
s.Add(client)
|
s.Add(client)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// Block until done, then remove.
|
// Block until done, then remove.
|
||||||
sshConn.Wait()
|
sshConn.Wait()
|
||||||
s.Remove(client)
|
s.Remove(client)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go client.handleChannels(channels)
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user