peer: add error chan to queueMsg
This commit is contained in:
parent
c36b1c3992
commit
25b77a0aee
19
peer.go
19
peer.go
@ -49,7 +49,7 @@ const (
|
||||
// buffered channel acts as a semaphore to be used for synchronization purposes.
|
||||
type outgoinMsg struct {
|
||||
msg lnwire.Message
|
||||
sentChan chan struct{} // MUST be buffered.
|
||||
errChan chan error // MUST be buffered.
|
||||
}
|
||||
|
||||
// newChannelMsg packages a lnwallet.LightningChannel with a channel that
|
||||
@ -1027,8 +1027,8 @@ out:
|
||||
// callers to optionally synchronize sends with the
|
||||
// writeHandler.
|
||||
err := p.writeMessage(outMsg.msg)
|
||||
if outMsg.sentChan != nil {
|
||||
close(outMsg.sentChan)
|
||||
if outMsg.errChan != nil {
|
||||
outMsg.errChan <- err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@ -1122,12 +1122,17 @@ func (p *peer) PingTime() int64 {
|
||||
}
|
||||
|
||||
// queueMsg queues a new lnwire.Message to be eventually sent out on the
|
||||
// wire.
|
||||
func (p *peer) queueMsg(msg lnwire.Message, doneChan chan struct{}) {
|
||||
// wire. It returns an error if we failed to queue the message. An error
|
||||
// is sent on errChan if the message fails being sent to the peer, or
|
||||
// nil otherwise.
|
||||
func (p *peer) queueMsg(msg lnwire.Message, errChan chan error) {
|
||||
select {
|
||||
case p.outgoingQueue <- outgoinMsg{msg, doneChan}:
|
||||
case p.outgoingQueue <- outgoinMsg{msg, errChan}:
|
||||
case <-p.quit:
|
||||
return
|
||||
peerLog.Debugf("Peer shutting down, could not enqueue msg.")
|
||||
if errChan != nil {
|
||||
errChan <- fmt.Errorf("peer shutting down")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user