Skip to content

Commit

Permalink
Only open a message sender when we have messages to send
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
  • Loading branch information
whyrusleeping committed Jul 16, 2017
1 parent 06c567d commit a93b44b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions exchange/bitswap/wantmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,6 @@ func (mq *msgQueue) runQueue(ctx context.Context) {
}

func (mq *msgQueue) doWork(ctx context.Context) {
if mq.sender == nil {
err := mq.openSender(ctx)
if err != nil {
log.Infof("cant open message sender to peer %s: %s", mq.p, err)
// TODO: cant connect, what now?
return
}
}

// grab outgoing message
mq.outlk.Lock()
wlm := mq.out
Expand All @@ -206,6 +197,16 @@ func (mq *msgQueue) doWork(ctx context.Context) {
mq.out = nil
mq.outlk.Unlock()

// NB: only open a stream if we actually have data to send
if mq.sender == nil {
err := mq.openSender(ctx)
if err != nil {
log.Infof("cant open message sender to peer %s: %s", mq.p, err)
// TODO: cant connect, what now?
return
}
}

// send wantlist updates
for { // try to send this message until we fail.
err := mq.sender.SendMsg(ctx, wlm)
Expand Down

0 comments on commit a93b44b

Please sign in to comment.