From 3bc564058072a79a22320f8c5bc50e8844896114 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 8 Aug 2019 15:14:09 +0200 Subject: [PATCH] Add a flag to prevent partial writes on a UTCP connection. --- utcp.c | 14 ++++++++++++++ utcp.h | 1 + 2 files changed, 15 insertions(+) diff --git a/utcp.c b/utcp.c index d837d27..5938ea5 100644 --- a/utcp.c +++ b/utcp.c @@ -611,6 +611,20 @@ ssize_t utcp_send(struct utcp_connection *c, const void *data, size_t len) { return -1; } + // Check if we need to be able to buffer all data + + if(c->flags & UTCP_NO_PARTIAL) { + if(len > buffer_free(&c->sndbuf)) { + if(len > c->sndbuf.maxsize) { + errno = EMSGSIZE; + return -1; + } else { + errno = EWOULDBLOCK; + return 0; + } + } + } + // Add data to send buffer. len = buffer_put(&c->sndbuf, data, len); diff --git a/utcp.h b/utcp.h index 4b7075b..c570b32 100644 --- a/utcp.h +++ b/utcp.h @@ -49,6 +49,7 @@ struct utcp_connection; #define UTCP_RELIABLE 2 #define UTCP_FRAMED 4 #define UTCP_DROP_LATE 8 +#define UTCP_NO_PARTIAL 16 #define UTCP_TCP 3 #define UTCP_UDP 0 -- 2.39.2