diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-02-15 00:42:19 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2011-02-15 01:01:44 +0100 |
commit | 76681bafa8013f3dac2a6b66841720e8fc78d76d (patch) | |
tree | 7fed3af4996bba99f29bd164f0f9738f0af97037 | |
parent | b05552b14c8ac5918c9d88a568bdfc85cfe45755 (diff) |
write_queue: Only pop the queue if it is not empty
It is possible that the queue is cleared after the select
and before the callback for writable is called. Check if
the list is not empty brefore taking an item out of it.
-rw-r--r-- | src/write_queue.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/write_queue.c b/src/write_queue.c index 618a8c0b..7295569a 100644 --- a/src/write_queue.c +++ b/src/write_queue.c @@ -39,16 +39,18 @@ int write_queue_bfd_cb(struct bsc_fd *fd, unsigned int what) struct msgb *msg; fd->when &= ~BSC_FD_WRITE; - msg = msgb_dequeue(&queue->msg_queue); - if (!msg) - return -1; - --queue->current_length; - queue->write_cb(fd, msg); - msgb_free(msg); + /* the queue might have been emptied */ + if (!llist_empty(&queue->msg_queue)) { + --queue->current_length; + + msg = msgb_dequeue(&queue->msg_queue); + queue->write_cb(fd, msg); + msgb_free(msg); - if (!llist_empty(&queue->msg_queue)) - fd->when |= BSC_FD_WRITE; + if (!llist_empty(&queue->msg_queue)) + fd->when |= BSC_FD_WRITE; + } } return 0; |