ergochat / irc-go

Libraries to help with IRC development in Go.
ISC License
41 stars 6 forks source link

fix #79 #81

Closed slingamn closed 2 years ago

slingamn commented 2 years ago

An explicit Reconnect() should interrupt the ReconnectFreq-based delay between automatic reconnection attempts.

Testing patch:

diff --git a/ircevent/examples/simple.go b/ircevent/examples/simple.go
index 70d9270..8e08de2 100644
--- a/ircevent/examples/simple.go
+++ b/ircevent/examples/simple.go
@@ -4,6 +4,8 @@ import (
    "crypto/tls"
    "log"
    "os"
+   "os/signal"
+   "syscall"
    "strconv"
    "strings"

@@ -63,6 +65,14 @@ func main() {
            irc.Privmsg(e.Params[0], e.Params[2])
        }
    })
+   reconnSignal := make(chan os.Signal, 1)
+   signal.Notify(reconnSignal, syscall.SIGHUP)
+   go func() {
+       for _ = range reconnSignal {
+           log.Printf("signal caught\n")
+           irc.Reconnect()
+       }
+   }()
    // example client-to-client extension via message-tags:
    // have the bot maintain a running sum of integers
    var sum int64 // doesn't need synchronization as long as it's only visible from a single callback