]> git.meshlink.io Git - utcp/blobdiff - utcp.c
Add a flag to prevent partial writes on a UTCP connection.
[utcp] / utcp.c
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;
        }
 
+       // 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);