]> git.meshlink.io Git - utcp/commitdiff
Add a flag to prevent partial writes on a UTCP connection.
authorGuus Sliepen <guus@sliepen.org>
Thu, 8 Aug 2019 13:14:09 +0000 (15:14 +0200)
committerGuus Sliepen <guus@sliepen.org>
Thu, 8 Aug 2019 13:14:09 +0000 (15:14 +0200)
utcp.c
utcp.h

diff --git a/utcp.c b/utcp.c
index d837d27a1b96fe05b860ce8fcf692bbda115f092..5938ea5bcea6af1a99b9d2e885b8fd68bdf70435 100644 (file)
--- 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;
        }
 
                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);
        // Add data to send buffer.
 
        len = buffer_put(&c->sndbuf, data, len);
diff --git a/utcp.h b/utcp.h
index 4b7075b56520eb79e4c3600ed7ca6427d0421b56..c570b3231be88b06e98c4d47cca5e35cd8d762c3 100644 (file)
--- 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_RELIABLE 2
 #define UTCP_FRAMED 4
 #define UTCP_DROP_LATE 8
+#define UTCP_NO_PARTIAL 16
 
 #define UTCP_TCP 3
 #define UTCP_UDP 0
 
 #define UTCP_TCP 3
 #define UTCP_UDP 0