From ed74e12b6d13b970945c9660e220d7dec1cd701b Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Fri, 12 Dec 2014 00:42:02 -0800 Subject: [PATCH] Fix buffer fill stuck.; --- README.md | 2 ++ server.go | 17 ++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 4b62e0d..9e67eb1 100644 --- a/README.md +++ b/README.md @@ -55,3 +55,5 @@ things up with `make run`. * [ ] Lots of refactoring * [ ] Pull out the chat-related stuff into isolation from the ssh serving stuff + +* Fix hanging on collision connect diff --git a/server.go b/server.go index e3b7a06..2b23b69 100644 --- a/server.go +++ b/server.go @@ -74,20 +74,17 @@ func (s *Server) Broadcast(msg string, except *Client) { } func (s *Server) Add(client *Client) { - for _, msg := range s.history.Get(10) { - if msg == "" { - continue - } - client.Msg <- msg - } - client.Msg <- fmt.Sprintf("-> Welcome to ssh-chat. Enter /help for more.\r\n") + go func() { + client.WriteLines(s.history.Get(10)) + client.Write(fmt.Sprintf("-> Welcome to ssh-chat. Enter /help for more.\r\n")) + }() s.lock.Lock() s.count++ newName, err := s.proposeName(client.Name) if err != nil { - client.Msg <- fmt.Sprintf("-> Your name '%s' is not avaialble, renamed to '%s'. Use /nick to change it.\r\n", client.Name, newName) + client.Msg <- fmt.Sprintf("-> Your name '%s' is not available, renamed to '%s'. Use /nick to change it.\r\n", client.Name, newName) } client.Name = newName @@ -196,15 +193,13 @@ func (s *Server) Start(laddr string) error { go ssh.DiscardRequests(requests) client := NewClient(s, sshConn) + client.handleChannels(channels) s.Add(client) - go func() { // Block until done, then remove. sshConn.Wait() s.Remove(client) }() - - go client.handleChannels(channels) }() } }()