From 7db4347419c4e28fb1eb2cbeb62054ce8b50d987 Mon Sep 17 00:00:00 2001 From: Jeremy Latt Date: Thu, 13 Mar 2014 17:19:39 -0700 Subject: [PATCH] bind to listening sockets before asyncing --- irc/server.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/irc/server.go b/irc/server.go index b332b882..c6ccc7c4 100644 --- a/irc/server.go +++ b/irc/server.go @@ -70,7 +70,7 @@ func NewServer(config *Config) *Server { server.loadChannels() for _, addr := range config.Server.Listen { - go server.listen(addr) + server.listen(addr) } signal.Notify(server.signals, SERVER_SIGNALS...) @@ -189,16 +189,18 @@ func (s *Server) listen(addr string) { Log.info.Printf("%s listening on %s", s, addr) - for { - conn, err := listener.Accept() - if err != nil { - Log.error.Printf("%s accept error: %s", s, err) - continue - } - Log.debug.Printf("%s accept: %s", s, conn.RemoteAddr()) + go func() { + for { + conn, err := listener.Accept() + if err != nil { + Log.error.Printf("%s accept error: %s", s, err) + continue + } + Log.debug.Printf("%s accept: %s", s, conn.RemoteAddr()) - s.newConns <- conn - } + s.newConns <- conn + } + }() } //