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.
This commit is contained in:
Holger Hans Peter Freyther 2011-02-15 00:42:19 +01:00
parent b05552b14c
commit 76681bafa8
1 changed files with 10 additions and 8 deletions

View File

@ -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;
if (!llist_empty(&queue->msg_queue))
fd->when |= BSC_FD_WRITE;
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;
}
}
return 0;