+(defun riece-flush-send-queue (process)
+ (with-current-buffer (process-buffer process)
+ (let ((length 0)
+ (total 0)
+ string)
+ (while (and riece-send-queue
+ (< total riece-max-send-size))
+ (setq string (riece-encode-coding-string (car riece-send-queue))
+ length (length string))
+ (if (> length riece-max-send-size)
+ (message "Long message (%d > %d)" length riece-max-send-size)
+ (process-send-string process string)
+ (setq total (+ total length)))
+ (setq riece-send-queue (cdr riece-send-queue)))
+ (if riece-send-queue
+ (progn
+ (if riece-debug
+ (message "%d bytes sent, %d bytes left"
+ total (apply #'+ (mapcar #'length riece-send-queue))))
+ ;; schedule next send after a second
+ (riece-run-at-time 1 nil
+ #'riece-flush-send-queue process))
+ (if riece-debug
+ (message "%d bytes sent" total))))))
+