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:
parent
8b8321be96
commit
79ac1741ea
19
irc.go
19
irc.go
@ -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) {
|
func (irc *IRCConnection) Join(channel string) {
|
||||||
irc.pwrite <- fmt.Sprintf("JOIN %s\r\n", channel)
|
irc.pwrite <- fmt.Sprintf("JOIN %s\r\n", channel)
|
||||||
}
|
}
|
||||||
@ -133,12 +143,19 @@ func (i *IRCConnection) Reconnect() os.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *IRCConnection) Loop() {
|
func (i *IRCConnection) Loop() {
|
||||||
for {
|
for !i.quitting {
|
||||||
e := <-i.Error
|
e := <-i.Error
|
||||||
|
if i.quitting {
|
||||||
|
break
|
||||||
|
}
|
||||||
fmt.Printf("Error: %s\n", e)
|
fmt.Printf("Error: %s\n", e)
|
||||||
error = true
|
error = true
|
||||||
i.Reconnect()
|
i.Reconnect()
|
||||||
}
|
}
|
||||||
|
close(i.pwrite)
|
||||||
|
close(i.pread)
|
||||||
|
<-i.syncreader
|
||||||
|
<-i.syncwriter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IRCConnection) Connect(server string) os.Error {
|
func (i *IRCConnection) Connect(server string) os.Error {
|
||||||
|
@ -24,6 +24,8 @@ type IRCConnection struct {
|
|||||||
lastMessage int64
|
lastMessage int64
|
||||||
ticker <-chan int64
|
ticker <-chan int64
|
||||||
ticker2 <-chan int64
|
ticker2 <-chan int64
|
||||||
|
|
||||||
|
quitting bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type IRCEvent struct {
|
type IRCEvent struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user