From 1c5578e87fc0fec0cf585c586462b982fa296101 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Fri, 23 Mar 2012 00:48:19 -0400 Subject: [PATCH] connection: Just look at buffer size and remove redundant n_fds_out Instead of maintaining a count of the fds in the buffer, just compute that from the buffer size. That way we don't get out of sync. --- src/connection.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/connection.c b/src/connection.c index ef8e3ae..ca4a24c 100644 --- a/src/connection.c +++ b/src/connection.c @@ -62,7 +62,6 @@ struct wl_closure { struct wl_connection { struct wl_buffer in, out; struct wl_buffer fds_in, fds_out; - int n_fds_out; int fd; void *data; wl_connection_update_func_t update; @@ -158,6 +157,12 @@ wl_buffer_copy(struct wl_buffer *b, void *data, size_t count) } } +static int +wl_buffer_size(struct wl_buffer *b) +{ + return b->head - b->tail; +} + struct wl_connection * wl_connection_create(int fd, wl_connection_update_func_t update, @@ -287,7 +292,6 @@ wl_connection_data(struct wl_connection *connection, uint32_t mask) } close_fds(&connection->fds_out); - connection->n_fds_out = 0; connection->out.tail += len; if (connection->out.tail == connection->out.head && @@ -397,13 +401,11 @@ wl_message_size_extra(const struct wl_message *message) static int wl_connection_put_fd(struct wl_connection *connection, int32_t fd) { - if (connection->n_fds_out + 1 > MAX_FDS_OUT) { + if (wl_buffer_size(&connection->fds_out) == MAX_FDS_OUT * sizeof fd) if (wl_connection_data(connection, WL_CONNECTION_WRITABLE)) return -1; - } wl_buffer_put(&connection->fds_out, &fd, sizeof fd); - connection->n_fds_out++; return 0; } -- 2.7.4