write_queue: Re-enqueue msgb if write_cb returns -EAGAIN

By adding this functionality, the write_cb() handler can "un-dequeue"
the msgb in case of some error.  The msgb might have been modified
meanwhile, e.g. due to a partial write already pulling some data off
the head of the msgb.

Change-Id: I97bb0d64ec991adf5dd0b3708e0c7cf029e03b5f
diff --git a/src/write_queue.c b/src/write_queue.c
index 422eda4..b208b25 100644
--- a/src/write_queue.c
+++ b/src/write_queue.c
@@ -68,10 +68,15 @@
 		/* the queue might have been emptied */
 		if (msg) {
 			rc = queue->write_cb(fd, msg);
-			msgb_free(msg);
-
-			if (rc == -EBADF)
+			if (rc == -EBADF) {
+				msgb_free(msg);
 				goto err_badfd;
+			} else if (rc == -EAGAIN) {
+				/* re-enqueue the msgb to the head of the queue */
+				llist_add(&msg->list, &queue->msg_queue);
+				queue->current_length++;
+			} else
+				msgb_free(msg);
 
 			if (!llist_empty(&queue->msg_queue))
 				fd->when |= OSMO_FD_WRITE;