connection: Rename wl_buffer
authorDerek Foreman <derek.foreman@collabora.com>
Fri, 6 Aug 2021 18:16:55 +0000 (13:16 -0500)
committerDerek Foreman <derek.foreman@collabora.com>
Mon, 9 Aug 2021 16:51:58 +0000 (11:51 -0500)
struct wl_buffer has other meaning in wayland, thus making this a pretty
confusing structure name. Function names like wl_buffer_put() just
compound the confusion.

Rename the struct and the associated functions (none of which are called
from outside this file anyway). The struct retains a wl_ prefix, as is
the custom for wayland internal data structures. The function names
have not retained this prefix, as we have many static function that
aren't prefixed.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
src/connection.c

index 1210772..ad16eee 100644 (file)
@@ -54,7 +54,7 @@ div_roundup(uint32_t n, size_t a)
        return (uint32_t) (((uint64_t) n + (a - 1)) / a);
 }
 
-struct wl_buffer {
+struct wl_ring_buffer {
        char data[4096];
        uint32_t head, tail;
 };
@@ -65,14 +65,14 @@ struct wl_buffer {
 #define CLEN           (CMSG_LEN(MAX_FDS_OUT * sizeof(int32_t)))
 
 struct wl_connection {
-       struct wl_buffer in, out;
-       struct wl_buffer fds_in, fds_out;
+       struct wl_ring_buffer in, out;
+       struct wl_ring_buffer fds_in, fds_out;
        int fd;
        int want_flush;
 };
 
 static int
-wl_buffer_put(struct wl_buffer *b, const void *data, size_t count)
+ring_buffer_put(struct wl_ring_buffer *b, const void *data, size_t count)
 {
        uint32_t head, size;
 
@@ -98,7 +98,7 @@ wl_buffer_put(struct wl_buffer *b, const void *data, size_t count)
 }
 
 static void
-wl_buffer_put_iov(struct wl_buffer *b, struct iovec *iov, int *count)
+ring_buffer_put_iov(struct wl_ring_buffer *b, struct iovec *iov, int *count)
 {
        uint32_t head, tail;
 
@@ -122,7 +122,7 @@ wl_buffer_put_iov(struct wl_buffer *b, struct iovec *iov, int *count)
 }
 
 static void
-wl_buffer_get_iov(struct wl_buffer *b, struct iovec *iov, int *count)
+ring_buffer_get_iov(struct wl_ring_buffer *b, struct iovec *iov, int *count)
 {
        uint32_t head, tail;
 
@@ -146,7 +146,7 @@ wl_buffer_get_iov(struct wl_buffer *b, struct iovec *iov, int *count)
 }
 
 static void
-wl_buffer_copy(struct wl_buffer *b, void *data, size_t count)
+ring_buffer_copy(struct wl_ring_buffer *b, void *data, size_t count)
 {
        uint32_t tail, size;
 
@@ -161,7 +161,7 @@ wl_buffer_copy(struct wl_buffer *b, void *data, size_t count)
 }
 
 static uint32_t
-wl_buffer_size(struct wl_buffer *b)
+ring_buffer_size(struct wl_ring_buffer *b)
 {
        return b->head - b->tail;
 }
@@ -181,16 +181,16 @@ wl_connection_create(int fd)
 }
 
 static void
-close_fds(struct wl_buffer *buffer, int max)
+close_fds(struct wl_ring_buffer *buffer, int max)
 {
        int32_t fds[sizeof(buffer->data) / sizeof(int32_t)], i, count;
        size_t size;
 
-       size = wl_buffer_size(buffer);
+       size = ring_buffer_size(buffer);
        if (size == 0)
                return;
 
-       wl_buffer_copy(buffer, fds, size);
+       ring_buffer_copy(buffer, fds, size);
        count = size / sizeof fds[0];
        if (max > 0 && max < count)
                count = max;
@@ -221,7 +221,7 @@ wl_connection_destroy(struct wl_connection *connection)
 void
 wl_connection_copy(struct wl_connection *connection, void *data, size_t size)
 {
-       wl_buffer_copy(&connection->in, data, size);
+       ring_buffer_copy(&connection->in, data, size);
 }
 
 void
@@ -231,12 +231,12 @@ wl_connection_consume(struct wl_connection *connection, size_t size)
 }
 
 static void
-build_cmsg(struct wl_buffer *buffer, char *data, int *clen)
+build_cmsg(struct wl_ring_buffer *buffer, char *data, int *clen)
 {
        struct cmsghdr *cmsg;
        size_t size;
 
-       size = wl_buffer_size(buffer);
+       size = ring_buffer_size(buffer);
        if (size > MAX_FDS_OUT * sizeof(int32_t))
                size = MAX_FDS_OUT * sizeof(int32_t);
 
@@ -245,7 +245,7 @@ build_cmsg(struct wl_buffer *buffer, char *data, int *clen)
                cmsg->cmsg_level = SOL_SOCKET;
                cmsg->cmsg_type = SCM_RIGHTS;
                cmsg->cmsg_len = CMSG_LEN(size);
-               wl_buffer_copy(buffer, CMSG_DATA(cmsg), size);
+               ring_buffer_copy(buffer, CMSG_DATA(cmsg), size);
                *clen = cmsg->cmsg_len;
        } else {
                *clen = 0;
@@ -253,7 +253,7 @@ build_cmsg(struct wl_buffer *buffer, char *data, int *clen)
 }
 
 static int
-decode_cmsg(struct wl_buffer *buffer, struct msghdr *msg)
+decode_cmsg(struct wl_ring_buffer *buffer, struct msghdr *msg)
 {
        struct cmsghdr *cmsg;
        size_t size, max, i;
@@ -266,13 +266,13 @@ decode_cmsg(struct wl_buffer *buffer, struct msghdr *msg)
                        continue;
 
                size = cmsg->cmsg_len - CMSG_LEN(0);
-               max = sizeof(buffer->data) - wl_buffer_size(buffer);
+               max = sizeof(buffer->data) - ring_buffer_size(buffer);
                if (size > max || overflow) {
                        overflow = 1;
                        size /= sizeof(int32_t);
                        for (i = 0; i < size; i++)
                                close(((int*)CMSG_DATA(cmsg))[i]);
-               } else if (wl_buffer_put(buffer, CMSG_DATA(cmsg), size) < 0) {
+               } else if (ring_buffer_put(buffer, CMSG_DATA(cmsg), size) < 0) {
                                return -1;
                }
        }
@@ -299,7 +299,7 @@ wl_connection_flush(struct wl_connection *connection)
 
        tail = connection->out.tail;
        while (connection->out.head - connection->out.tail > 0) {
-               wl_buffer_get_iov(&connection->out, iov, &count);
+               ring_buffer_get_iov(&connection->out, iov, &count);
 
                build_cmsg(&connection->fds_out, cmsg, &clen);
 
@@ -332,7 +332,7 @@ wl_connection_flush(struct wl_connection *connection)
 uint32_t
 wl_connection_pending_input(struct wl_connection *connection)
 {
-       return wl_buffer_size(&connection->in);
+       return ring_buffer_size(&connection->in);
 }
 
 int
@@ -343,12 +343,12 @@ wl_connection_read(struct wl_connection *connection)
        char cmsg[CLEN];
        int len, count, ret;
 
-       if (wl_buffer_size(&connection->in) >= sizeof(connection->in.data)) {
+       if (ring_buffer_size(&connection->in) >= sizeof(connection->in.data)) {
                errno = EOVERFLOW;
                return -1;
        }
 
-       wl_buffer_put_iov(&connection->in, iov, &count);
+       ring_buffer_put_iov(&connection->in, iov, &count);
 
        msg.msg_name = NULL;
        msg.msg_namelen = 0;
@@ -385,7 +385,7 @@ wl_connection_write(struct wl_connection *connection,
                        return -1;
        }
 
-       if (wl_buffer_put(&connection->out, data, count) < 0)
+       if (ring_buffer_put(&connection->out, data, count) < 0)
                return -1;
 
        connection->want_flush = 1;
@@ -404,7 +404,7 @@ wl_connection_queue(struct wl_connection *connection,
                        return -1;
        }
 
-       return wl_buffer_put(&connection->out, data, count);
+       return ring_buffer_put(&connection->out, data, count);
 }
 
 int
@@ -429,13 +429,13 @@ wl_connection_get_fd(struct wl_connection *connection)
 static int
 wl_connection_put_fd(struct wl_connection *connection, int32_t fd)
 {
-       if (wl_buffer_size(&connection->fds_out) == MAX_FDS_OUT * sizeof fd) {
+       if (ring_buffer_size(&connection->fds_out) == MAX_FDS_OUT * sizeof fd) {
                connection->want_flush = 1;
                if (wl_connection_flush(connection) < 0)
                        return -1;
        }
 
-       return wl_buffer_put(&connection->fds_out, &fd, sizeof fd);
+       return ring_buffer_put(&connection->fds_out, &fd, sizeof fd);
 }
 
 const char *
@@ -849,7 +849,7 @@ wl_connection_demarshal(struct wl_connection *connection,
                                goto err;
                        }
 
-                       wl_buffer_copy(&connection->fds_in, &fd, sizeof fd);
+                       ring_buffer_copy(&connection->fds_in, &fd, sizeof fd);
                        connection->fds_in.tail += sizeof fd;
                        closure->args[i].h = fd;
                        break;