From e4261d73b806cbfcf824646a1f07f2d4b6cacdf7 Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Sat, 24 Aug 2013 08:36:57 +0100 Subject: [PATCH] Some tweaking --- client.go | 10 ++++------ main.go | 20 ++++++++++---------- server.go | 17 +++-------------- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/client.go b/client.go index 5ac1baa..a9c6059 100644 --- a/client.go +++ b/client.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "log" "sort" "strings" "time" @@ -159,8 +158,6 @@ func (c *Client) reply(code int, args ...string) { } func (c *Client) clientThread() { - defer c.connection.Close() - readSignalChan := make(chan int, 3) writeSignalChan := make(chan int, 3) writeChan := make(chan string, 100) @@ -175,6 +172,8 @@ func (c *Client) clientThread() { } delete(c.server.clientMap, c.nick) + + c.connection.Close() }() for { @@ -188,10 +187,9 @@ func (c *Client) clientThread() { case line := <-c.outputChan: select { case writeChan <- line: - //It worked + continue default: - log.Printf("Dropped a line for client: %q", c.nick) - //Do nothing, dropping the line + c.disconnect() } } } diff --git a/main.go b/main.go index 0d366c4..3fce8e9 100644 --- a/main.go +++ b/main.go @@ -8,17 +8,16 @@ import ( "strings" ) +var ( + tlsKeyFile = flag.String("tls-key", "tls.key", "The private key file used for TLS") + tlsCertFile = flag.String("tls-cert", "tls.crt", "The certificate file used for TLS") + ircAddress = flag.String("irc-address", ":6697", "The address:port to bind to and listen for clients on") + serverName = flag.String("irc-servername", "rosella", "Server name displayed to clients") + authFile = flag.String("irc-authfile", "", "File containing usernames and passwords of operators.") +) + func main() { - tlsKeyFile := flag.String("tls-key", "tls.key", "The private key file used for TLS") - tlsCertFile := flag.String("tls-cert", "tls.crt", "The certificate file used for TLS") - - ircAddress := flag.String("irc-address", ":6697", "The address:port to bind to and listen for clients on") - - serverName := flag.String("irc-servername", "rosella", "Server name displayed to clients") - - authFile := flag.String("irc-authfile", "", "File containing usernames and passwords of operators.") - flag.Parse() log.Printf("Rosella Initialising.") @@ -52,7 +51,8 @@ func main() { } } } - server.Run() + + go server.Run() tlsConfig := new(tls.Config) diff --git a/server.go b/server.go index 811c3ea..9796ef2 100644 --- a/server.go +++ b/server.go @@ -4,7 +4,6 @@ import ( "crypto/sha1" "fmt" "io" - "log" "net" "regexp" "strings" @@ -24,19 +23,9 @@ func NewServer() *Server { } func (s *Server) Run() { - go func() { - for event := range s.eventChan { - defer func() { - if err := recover(); err != nil { - log.Printf("Recovered from panic()") - log.Printf("%s sent %q", event.client.nick, event.input) - log.Println(err) - } - }() - - s.handleEvent(<-s.eventChan) - } - }() + for event := range s.eventChan { + s.handleEvent(<-s.eventChan) + } } func (s *Server) HandleConnection(conn net.Conn) {