return (uint32_t) (((uint64_t) n + (a - 1)) / a);
}
-struct wl_buffer {
+struct wl_ring_buffer {
char data[4096];
uint32_t head, tail;
};
#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;
}
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;
}
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;
}
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;
}
static uint32_t
-wl_buffer_size(struct wl_buffer *b)
+ring_buffer_size(struct wl_ring_buffer *b)
{
return b->head - b->tail;
}
}
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;
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
}
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);
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;
}
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;
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;
}
}
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);
uint32_t
wl_connection_pending_input(struct wl_connection *connection)
{
- return wl_buffer_size(&connection->in);
+ return ring_buffer_size(&connection->in);
}
int
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;
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;
return -1;
}
- return wl_buffer_put(&connection->out, data, count);
+ return ring_buffer_put(&connection->out, data, count);
}
int
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 *
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;