From 82d1050496bba249326c29588c5c2b81657b1ff6 Mon Sep 17 00:00:00 2001 From: tj Date: Wed, 25 Nov 2009 19:17:08 +0100 Subject: [PATCH] Add reconnect --- irc.go | 11 ++++++++++- irc_struct.go | 6 ++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/irc.go b/irc.go index 452d567..8f77baf 100644 --- a/irc.go +++ b/irc.go @@ -201,9 +201,18 @@ func (irc *IRCConnection) Privmsg(target, message string) { irc.pwrite <- fmt.Sprintf("PRIVMSG %s :%s\r\n", target, message) } +//Try to reconnect +func (irc *IRCConnection) Reconnect() os.Error { + irc.socket, irc.Error = net.Dial("tcp", "", irc.server); + if irc.Error != nil { + return irc.Error + } + return nil; +} + func IRC(server string, nick string, user string, events chan *IRCEvent) (*IRCConnection, os.Error) { irc := new(IRCConnection); - + irc.server = server; irc.socket, irc.Error = net.Dial("tcp", "", server); if irc.Error != nil { return nil, irc.Error diff --git a/irc_struct.go b/irc_struct.go index 612efa0..14f4618 100644 --- a/irc_struct.go +++ b/irc_struct.go @@ -10,6 +10,7 @@ import ( ) type IRCEventCode int + const ( IRC_NOTICE_AUTH IRCEventCode = 1 << iota; IRC_PING; @@ -49,9 +50,10 @@ type IRCConnection struct { perror chan os.Error; EventChan chan *IRCEvent; Error os.Error; - nick string; - user string; + nick string; + user string; registered bool; + server string; } type IRCEvent struct {