From da8b1c1d1baafb9cf4a0cc9a88362f161f8d1319 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 20 Apr 2020 18:58:00 +0200 Subject: First commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libaxl_flush.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 libaxl_flush.c (limited to 'libaxl_flush.c') diff --git a/libaxl_flush.c b/libaxl_flush.c new file mode 100644 index 0000000..848dbe5 --- /dev/null +++ b/libaxl_flush.c @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +int +libaxl_flush(LIBAXL_CONNECTION *restrict conn, int flags) +{ + LIBAXL_CONTEXT *ctx; + ssize_t r; + + WLOCK_CONNECTION_SEND(conn); + + while ((ctx = conn->pending_out)) { + while (ctx->out_progress < ctx->out_length) { + r = liberror_send(conn->fd, &ctx->out_buf[ctx->out_progress], + ctx->out_length - ctx->out_progress, flags, ""); + if (r < 0) { + WUNLOCK_CONNECTION_SEND(conn); + return LIBAXL_ERROR_SYSTEM; + } + ctx->out_progress += (size_t)r; + } + + conn->pending_out = ctx->next_pending_out; + libaxl_context_free(ctx); + } + + WUNLOCK_CONNECTION_SEND(conn); + + return 0; +} -- cgit v1.2.3-70-g09d2