summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-03-23 00:48:19 -0400
committerKristian Høgsberg <krh@bitplanet.net>2012-03-23 00:48:19 -0400
commit1c5578e87fc0fec0cf585c586462b982fa296101 (patch)
treec0e705c33dc4521c1b84eee2d4e605c6552ba210
parentcab70c9e5d8c38260a07bb1ddb7618826a120465 (diff)
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.
-rw-r--r--src/connection.c12
1 files 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;
}