Changeset 757 in code for trunk/conn.go


Ignore:
Timestamp:
Dec 8, 2021, 5:03:40 PM (4 years ago)
Author:
contact
Message:

Add context to {conn,upstreamConn}.SendMessage

This avoids blocking on upstream message rate limiting for too
long.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/conn.go

    r748 r757  
    218218// If the connection is closed before the message is sent, SendMessage silently
    219219// drops the message.
    220 func (c *conn) SendMessage(msg *irc.Message) {
     220func (c *conn) SendMessage(ctx context.Context, msg *irc.Message) {
    221221        c.lock.Lock()
    222222        defer c.lock.Unlock()
     
    225225                return
    226226        }
    227         c.outgoing <- msg
     227
     228        select {
     229        case c.outgoing <- msg:
     230                // Success
     231        case <-ctx.Done():
     232                c.logger.Printf("failed to send message: %v", ctx.Err())
     233        }
    228234}
    229235
Note: See TracChangeset for help on using the changeset viewer.