about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--btpd/peer.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/btpd/peer.c b/btpd/peer.c
index cc57a5d..c3de819 100644
--- a/btpd/peer.c
+++ b/btpd/peer.c
@@ -310,6 +310,8 @@ peer_on_cancel(struct peer *p, uint32_t index, uint32_t begin,
     uint32_t length)
 {
     struct nb_link *nl = BTPDQ_FIRST(&p->outq);
+    if (nl == NULL)
+	return;
     while (nl != NULL) {
 	if (nl->nb->info.type == NB_PIECE
 	    && nl->nb->info.index == index
@@ -327,6 +329,14 @@ peer_on_cancel(struct peer *p, uint32_t index, uint32_t begin,
 	}
 	nl = BTPDQ_NEXT(nl, entry);
     }
+
+    if (BTPDQ_EMPTY(&p->outq)) {
+	if (p->flags & PF_ON_WRITEQ) {
+	    BTPDQ_REMOVE(&btpd.writeq, p, wq_entry);
+	    p->flags &= ~PF_ON_WRITEQ;
+	} else
+	    event_del(&p->out_ev);
+    }
 }
 
 int