Add irccon.Quit() and irccon.Cycle()

Quit() Sends QUIT to server and exits the main loop.
Cycle() Sends QUIT to server and reconnects.
This commit is contained in:
tj 2010-10-18 21:46:34 +02:00
parent 8b8321be96
commit 79ac1741ea
2 changed files with 30 additions and 11 deletions

19
irc.go
View File

@ -92,6 +92,16 @@ func pinger(i *IRCConnection) {
}
}
func (irc *IRCConnection) Cycle() {
irc.SendRaw("QUIT")
irc.Reconnect()
}
func (irc *IRCConnection) Quit() {
irc.quitting = true
irc.SendRaw("QUIT")
}
func (irc *IRCConnection) Join(channel string) {
irc.pwrite <- fmt.Sprintf("JOIN %s\r\n", channel)
}
@ -133,12 +143,19 @@ func (i *IRCConnection) Reconnect() os.Error {
}
func (i *IRCConnection) Loop() {
for {
for !i.quitting {
e := <-i.Error
if i.quitting {
break
}
fmt.Printf("Error: %s\n", e)
error = true
i.Reconnect()
}
close(i.pwrite)
close(i.pread)
<-i.syncreader
<-i.syncwriter
}
func (i *IRCConnection) Connect(server string) os.Error {

View File

@ -24,6 +24,8 @@ type IRCConnection struct {
lastMessage int64
ticker <-chan int64
ticker2 <-chan int64
quitting bool
}
type IRCEvent struct {