Use append built-in instead of custom function

This commit is contained in:
tj
2010-11-19 19:26:27 +01:00
4 changed files with 52 additions and 58 deletions

33
irc.go
View File

@@ -59,7 +59,7 @@ func reader(irc *IRCConnection) {
}
func writer(irc *IRCConnection) {
for !error {
for !error && !closed(irc.pwrite) {
b := []byte(<-irc.pwrite)
if b == nil || irc.socket == nil {
break
@@ -76,24 +76,40 @@ func writer(irc *IRCConnection) {
//Pings the server if we have not recived any messages for 5 minutes
func pinger(i *IRCConnection) {
i.ticker = time.Tick(1000 * 1000 * 1000 * 60 * 4) //Every 4 minutes
i.ticker2 = time.Tick(1000 * 1000 * 1000 * 60 * 15) //Every 15 minutes
i.ticker = time.Tick(1000 * 1000 * 1000 * 60 * 1) //Tick every minute.
i.ticker2 = time.Tick(1000 * 1000 * 1000 * 60 * 15) //Tick every 15 minutes.
for {
select {
case <-i.ticker:
if time.Seconds()-i.lastMessage > 60*4 {
//Ping if we haven't recived anything from the server within 4 minutes
if time.Seconds()-i.lastMessage >= 60*4 {
i.SendRaw(fmt.Sprintf("PING %d", time.Nanoseconds()))
}
case <-i.ticker2:
//Ping every 15 minutes.
i.SendRaw(fmt.Sprintf("PING %d", time.Nanoseconds()))
}
}
}
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)
}
func (irc *IRCConnection) Part(channel string) {
irc.pwrite <- fmt.Sprintf("PART %s\r\n", channel)
}
func (irc *IRCConnection) Notice(target, message string) {
irc.pwrite <- fmt.Sprintf("NOTICE %s :%s\r\n", target, message)
}
@@ -131,12 +147,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 {