From c10849b4c0862450a2575726578d929c6e308635 Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 25 Sep 2013 23:37:11 -0400 Subject: [PATCH] Loop: catch reconnection errors; writeLoop: only log.Print if Debug --- irc.go | 13 +++++++++++-- irc_callback.go | 4 +++- irc_struct.go | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/irc.go b/irc.go index 91588cd..0aec775 100644 --- a/irc.go +++ b/irc.go @@ -74,7 +74,9 @@ func (irc *Connection) writeLoop() { break } - irc.log.Printf("--> %s\n", b) + if irc.Debug { + irc.log.Printf("--> %s\n", b) + } _, err := irc.socket.Write([]byte(b)) if err != nil { irc.Error <- err @@ -120,7 +122,14 @@ func (irc *Connection) Loop() { } irc.log.Printf("Error: %s\n", err) irc.Disconnect() - irc.Connect(irc.server) + for !irc.stopped { + if err = irc.Connect(irc.server); err != nil { + irc.log.Printf("Error: %s\n", err) + time.Sleep(1 * time.Second) + } else { + break + } + } } } diff --git a/irc_callback.go b/irc_callback.go index 2c6bf1f..f717903 100644 --- a/irc_callback.go +++ b/irc_callback.go @@ -115,7 +115,9 @@ func (irc *Connection) setupCallbacks() { irc.AddCallback("PONG", func(e *Event) { ns, _ := strconv.ParseInt(e.Message, 10, 64) delta := time.Duration(time.Now().UnixNano() - ns) - irc.log.Printf("Lag: %vs\n", delta) + if irc.Debug { + irc.log.Printf("Lag: %vs\n", delta) + } }) irc.AddCallback("NICK", func(e *Event) { diff --git a/irc_struct.go b/irc_struct.go index e5081cb..fa4bb2b 100644 --- a/irc_struct.go +++ b/irc_struct.go @@ -12,6 +12,7 @@ import ( ) type Connection struct { + Debug bool Error chan error Password string UseTLS bool