Allow non-context Dialers

Dialers who don't implement DialContext but upgrade past https://github.com/fluffle/goirc/pull/109 (which is 2.5 years old but still) will break. This change falls back to the non-context dial method, where calls may take longer and time out, and goirc would give them a warning as well.
This commit is contained in:
Tamás Solymos 2023-11-22 17:24:19 +00:00 committed by Alex Bee
parent 8b460bc60f
commit ceced391f3
1 changed files with 17 additions and 8 deletions

View File

@ -413,15 +413,24 @@ func (conn *Conn) internalConnect(ctx context.Context) error {
return err
}
contextProxyDialer, ok := proxyDialer.(proxy.ContextDialer)
if !ok {
return errors.New("Dialer for proxy does not support context")
}
conn.proxyDialer = contextProxyDialer
logging.Info("irc.Connect(): Connecting to %s.", conn.cfg.Server)
if s, err := conn.proxyDialer.DialContext(ctx, "tcp", conn.cfg.Server); err == nil {
conn.sock = s
if ok {
conn.proxyDialer = contextProxyDialer
logging.Info("irc.Connect(): Connecting to %s.", conn.cfg.Server)
if s, err := conn.proxyDialer.DialContext(ctx, "tcp", conn.cfg.Server); err == nil {
conn.sock = s
} else {
return err
}
} else {
return err
logging.Warn("Dialer for proxy does not support context, please implement DialContext")
conn.proxyDialer = proxyDialer
logging.Info("irc.Connect(): Connecting to %s.", conn.cfg.Server)
if s, err := conn.proxyDialer.Dial("tcp", conn.cfg.Server); err == nil {
conn.sock = s
} else {
return err
}
}
} else {
logging.Info("irc.Connect(): Connecting to %s.", conn.cfg.Server)