Merge pull request #61 from goshuirc/timeouts

ircevent: avoid uses of time.After
This commit is contained in:
Shivaram Lingamneni 2021-05-10 13:33:24 -04:00 committed by GitHub
commit f5e0f875f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -673,11 +673,13 @@ func (irc *Connection) Connect() (err error) {
}
irc.Send("NICK", irc.PreferredNick())
irc.Send("USER", irc.User, "s", "e", realname)
timeout := time.NewTimer(irc.Timeout)
defer timeout.Stop()
select {
case <-irc.welcomeChan:
case <-irc.end:
err = ServerDisconnected
case <-time.After(irc.Timeout):
case <-timeout.C:
err = ServerTimedOut
}
return
@ -724,13 +726,16 @@ func (irc *Connection) negotiateCaps() error {
} else {
irc.Send("AUTHENTICATE", irc.SASLMech)
}
timeout := time.NewTimer(CAPTimeout)
defer timeout.Stop()
select {
case res := <-irc.saslChan:
if res.Failed {
return res.Err
}
case <-time.After(CAPTimeout):
// Raise an error if we can't authenticate with SASL.
case <-timeout.C:
// if we expect to be able to SASL, failure to SASL should be treated
// as a connection error:
return SASLFailed
case <-irc.end:
return ServerDisconnected