Lift up context to downstreamConn.handleMessage

This commit is contained in:
Simon Ser 2021-11-17 12:38:08 +01:00
parent e28332a5aa
commit eb47f0dcd7
1 changed files with 7 additions and 10 deletions

View File

@ -615,22 +615,22 @@ func (dc *downstreamConn) marshalMessage(msg *irc.Message, net *network) *irc.Me
} }
func (dc *downstreamConn) handleMessage(msg *irc.Message) error { func (dc *downstreamConn) handleMessage(msg *irc.Message) error {
ctx, cancel := context.WithTimeout(context.TODO(), handleDownstreamMessageTimeout)
defer cancel()
switch msg.Command { switch msg.Command {
case "QUIT": case "QUIT":
return dc.Close() return dc.Close()
default: default:
if dc.registered { if dc.registered {
return dc.handleMessageRegistered(msg) return dc.handleMessageRegistered(ctx, msg)
} else { } else {
return dc.handleMessageUnregistered(msg) return dc.handleMessageUnregistered(ctx, msg)
} }
} }
} }
func (dc *downstreamConn) handleMessageUnregistered(msg *irc.Message) error { func (dc *downstreamConn) handleMessageUnregistered(ctx context.Context, msg *irc.Message) error {
ctx, cancel := context.WithTimeout(context.TODO(), handleDownstreamMessageTimeout)
defer cancel()
switch msg.Command { switch msg.Command {
case "NICK": case "NICK":
var nick string var nick string
@ -1416,10 +1416,7 @@ func (dc *downstreamConn) runUntilRegistered() error {
return nil return nil
} }
func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.Message) error {
ctx, cancel := context.WithTimeout(context.TODO(), handleDownstreamMessageTimeout)
defer cancel()
switch msg.Command { switch msg.Command {
case "CAP": case "CAP":
var subCmd string var subCmd string