From: Guus Sliepen Date: Thu, 8 Aug 2019 13:14:09 +0000 (+0200) Subject: Add a flag to prevent partial writes on a UTCP connection. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=3bc564058072a79a22320f8c5bc50e8844896114;p=utcp Add a flag to prevent partial writes on a UTCP connection. --- 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