mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-02-26 01:40:41 -05:00
connection: Rename wl_buffer
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>
This commit is contained in:
parent
0e0274af0c
commit
f736f11f99
1 changed files with 27 additions and 27 deletions
|
|
@ -54,7 +54,7 @@ div_roundup(uint32_t n, size_t a)
|
||||||
return (uint32_t) (((uint64_t) n + (a - 1)) / a);
|
return (uint32_t) (((uint64_t) n + (a - 1)) / a);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wl_buffer {
|
struct wl_ring_buffer {
|
||||||
char data[4096];
|
char data[4096];
|
||||||
uint32_t head, tail;
|
uint32_t head, tail;
|
||||||
};
|
};
|
||||||
|
|
@ -65,14 +65,14 @@ struct wl_buffer {
|
||||||
#define CLEN (CMSG_LEN(MAX_FDS_OUT * sizeof(int32_t)))
|
#define CLEN (CMSG_LEN(MAX_FDS_OUT * sizeof(int32_t)))
|
||||||
|
|
||||||
struct wl_connection {
|
struct wl_connection {
|
||||||
struct wl_buffer in, out;
|
struct wl_ring_buffer in, out;
|
||||||
struct wl_buffer fds_in, fds_out;
|
struct wl_ring_buffer fds_in, fds_out;
|
||||||
int fd;
|
int fd;
|
||||||
int want_flush;
|
int want_flush;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
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;
|
uint32_t head, size;
|
||||||
|
|
||||||
|
|
@ -98,7 +98,7 @@ wl_buffer_put(struct wl_buffer *b, const void *data, size_t count)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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;
|
uint32_t head, tail;
|
||||||
|
|
||||||
|
|
@ -122,7 +122,7 @@ wl_buffer_put_iov(struct wl_buffer *b, struct iovec *iov, int *count)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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;
|
uint32_t head, tail;
|
||||||
|
|
||||||
|
|
@ -146,7 +146,7 @@ wl_buffer_get_iov(struct wl_buffer *b, struct iovec *iov, int *count)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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;
|
uint32_t tail, size;
|
||||||
|
|
||||||
|
|
@ -161,7 +161,7 @@ wl_buffer_copy(struct wl_buffer *b, void *data, size_t count)
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t
|
||||||
wl_buffer_size(struct wl_buffer *b)
|
ring_buffer_size(struct wl_ring_buffer *b)
|
||||||
{
|
{
|
||||||
return b->head - b->tail;
|
return b->head - b->tail;
|
||||||
}
|
}
|
||||||
|
|
@ -181,16 +181,16 @@ wl_connection_create(int fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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;
|
int32_t fds[sizeof(buffer->data) / sizeof(int32_t)], i, count;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
size = wl_buffer_size(buffer);
|
size = ring_buffer_size(buffer);
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wl_buffer_copy(buffer, fds, size);
|
ring_buffer_copy(buffer, fds, size);
|
||||||
count = size / sizeof fds[0];
|
count = size / sizeof fds[0];
|
||||||
if (max > 0 && max < count)
|
if (max > 0 && max < count)
|
||||||
count = max;
|
count = max;
|
||||||
|
|
@ -221,7 +221,7 @@ wl_connection_destroy(struct wl_connection *connection)
|
||||||
void
|
void
|
||||||
wl_connection_copy(struct wl_connection *connection, void *data, size_t size)
|
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
|
void
|
||||||
|
|
@ -231,12 +231,12 @@ wl_connection_consume(struct wl_connection *connection, size_t size)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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;
|
struct cmsghdr *cmsg;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
size = wl_buffer_size(buffer);
|
size = ring_buffer_size(buffer);
|
||||||
if (size > MAX_FDS_OUT * sizeof(int32_t))
|
if (size > MAX_FDS_OUT * sizeof(int32_t))
|
||||||
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_level = SOL_SOCKET;
|
||||||
cmsg->cmsg_type = SCM_RIGHTS;
|
cmsg->cmsg_type = SCM_RIGHTS;
|
||||||
cmsg->cmsg_len = CMSG_LEN(size);
|
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;
|
*clen = cmsg->cmsg_len;
|
||||||
} else {
|
} else {
|
||||||
*clen = 0;
|
*clen = 0;
|
||||||
|
|
@ -253,7 +253,7 @@ build_cmsg(struct wl_buffer *buffer, char *data, int *clen)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
decode_cmsg(struct wl_buffer *buffer, struct msghdr *msg)
|
decode_cmsg(struct wl_ring_buffer *buffer, struct msghdr *msg)
|
||||||
{
|
{
|
||||||
struct cmsghdr *cmsg;
|
struct cmsghdr *cmsg;
|
||||||
size_t size, max, i;
|
size_t size, max, i;
|
||||||
|
|
@ -266,13 +266,13 @@ decode_cmsg(struct wl_buffer *buffer, struct msghdr *msg)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
size = cmsg->cmsg_len - CMSG_LEN(0);
|
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) {
|
if (size > max || overflow) {
|
||||||
overflow = 1;
|
overflow = 1;
|
||||||
size /= sizeof(int32_t);
|
size /= sizeof(int32_t);
|
||||||
for (i = 0; i < size; i++)
|
for (i = 0; i < size; i++)
|
||||||
close(((int*)CMSG_DATA(cmsg))[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;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -299,7 +299,7 @@ wl_connection_flush(struct wl_connection *connection)
|
||||||
|
|
||||||
tail = connection->out.tail;
|
tail = connection->out.tail;
|
||||||
while (connection->out.head - connection->out.tail > 0) {
|
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);
|
build_cmsg(&connection->fds_out, cmsg, &clen);
|
||||||
|
|
||||||
|
|
@ -332,7 +332,7 @@ wl_connection_flush(struct wl_connection *connection)
|
||||||
uint32_t
|
uint32_t
|
||||||
wl_connection_pending_input(struct wl_connection *connection)
|
wl_connection_pending_input(struct wl_connection *connection)
|
||||||
{
|
{
|
||||||
return wl_buffer_size(&connection->in);
|
return ring_buffer_size(&connection->in);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
@ -343,12 +343,12 @@ wl_connection_read(struct wl_connection *connection)
|
||||||
char cmsg[CLEN];
|
char cmsg[CLEN];
|
||||||
int len, count, ret;
|
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;
|
errno = EOVERFLOW;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_buffer_put_iov(&connection->in, iov, &count);
|
ring_buffer_put_iov(&connection->in, iov, &count);
|
||||||
|
|
||||||
msg.msg_name = NULL;
|
msg.msg_name = NULL;
|
||||||
msg.msg_namelen = 0;
|
msg.msg_namelen = 0;
|
||||||
|
|
@ -385,7 +385,7 @@ wl_connection_write(struct wl_connection *connection,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wl_buffer_put(&connection->out, data, count) < 0)
|
if (ring_buffer_put(&connection->out, data, count) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
connection->want_flush = 1;
|
connection->want_flush = 1;
|
||||||
|
|
@ -404,7 +404,7 @@ wl_connection_queue(struct wl_connection *connection,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return wl_buffer_put(&connection->out, data, count);
|
return ring_buffer_put(&connection->out, data, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
@ -429,13 +429,13 @@ wl_connection_get_fd(struct wl_connection *connection)
|
||||||
static int
|
static int
|
||||||
wl_connection_put_fd(struct wl_connection *connection, int32_t fd)
|
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;
|
connection->want_flush = 1;
|
||||||
if (wl_connection_flush(connection) < 0)
|
if (wl_connection_flush(connection) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return wl_buffer_put(&connection->fds_out, &fd, sizeof fd);
|
return ring_buffer_put(&connection->fds_out, &fd, sizeof fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
|
@ -849,7 +849,7 @@ wl_connection_demarshal(struct wl_connection *connection,
|
||||||
goto err;
|
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;
|
connection->fds_in.tail += sizeof fd;
|
||||||
closure->args[i].h = fd;
|
closure->args[i].h = fd;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue