aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-04-22 13:49:35 -0400
committerKristian Høgsberg <krh@bitplanet.net>2012-04-22 13:49:35 -0400
commit1901d66ffca2a10a3f24b918e5a4de56646f4f11 (patch)
tree458ee62f9f555a7208a179f19073224850a4b7cc /src
parentconnection: Dont put fds in the connection until we send the closure (diff)
downloadwayland-1901d66ffca2a10a3f24b918e5a4de56646f4f11.tar
wayland-1901d66ffca2a10a3f24b918e5a4de56646f4f11.tar.gz
wayland-1901d66ffca2a10a3f24b918e5a4de56646f4f11.tar.bz2
wayland-1901d66ffca2a10a3f24b918e5a4de56646f4f11.tar.lz
wayland-1901d66ffca2a10a3f24b918e5a4de56646f4f11.tar.xz
wayland-1901d66ffca2a10a3f24b918e5a4de56646f4f11.tar.zst
wayland-1901d66ffca2a10a3f24b918e5a4de56646f4f11.zip
connection: Move closure object out of wl_connection
Diffstat (limited to 'src')
-rw-r--r--src/connection.c38
-rw-r--r--src/wayland-client.c31
-rw-r--r--src/wayland-private.h25
-rw-r--r--src/wayland-server.c50
4 files changed, 73 insertions, 71 deletions
diff --git a/src/connection.c b/src/connection.c
index 6967262..ffae35d 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -28,7 +28,6 @@
#include <stdio.h>
#include <errno.h>
#include <sys/uio.h>
-#include <ffi.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
@@ -48,16 +47,6 @@ struct wl_buffer {
#define MASK(i) ((i) & 4095)
-struct wl_closure {
- int count;
- const struct wl_message *message;
- ffi_type *types[20];
- ffi_cif cif;
- void *args[20];
- uint32_t buffer[256];
- uint32_t *start;
-};
-
#define MAX_FDS_OUT 28
#define CLEN (CMSG_LEN(MAX_FDS_OUT * sizeof(int32_t)))
@@ -412,13 +401,12 @@ wl_connection_put_fd(struct wl_connection *connection, int32_t fd)
return 0;
}
-struct wl_closure *
-wl_connection_vmarshal(struct wl_connection *connection,
- struct wl_object *sender,
- uint32_t opcode, va_list ap,
- const struct wl_message *message)
+int
+wl_closure_vmarshal(struct wl_closure *closure,
+ struct wl_object *sender,
+ uint32_t opcode, va_list ap,
+ const struct wl_message *message)
{
- struct wl_closure *closure = &connection->send_closure;
struct wl_object **objectp, *object;
uint32_t length, *p, *start, size, *end;
int dup_fd;
@@ -550,17 +538,18 @@ wl_connection_vmarshal(struct wl_connection *connection,
closure->message = message;
closure->count = count;
- return closure;
+ return 0;
err:
printf("request too big to marshal, maximum size is %zu\n",
sizeof closure->buffer);
errno = ENOMEM;
- return NULL;
+ return -1;
}
-struct wl_closure *
+int
wl_connection_demarshal(struct wl_connection *connection,
+ struct wl_closure *closure,
uint32_t size,
struct wl_map *objects,
const struct wl_message *message)
@@ -571,14 +560,13 @@ wl_connection_demarshal(struct wl_connection *connection,
unsigned int i, count, extra_space;
struct wl_object **object;
struct wl_array **array;
- struct wl_closure *closure = &connection->receive_closure;
count = strlen(message->signature) + 2;
if (count > ARRAY_LENGTH(closure->types)) {
printf("too many args (%d)\n", count);
errno = EINVAL;
wl_connection_consume(connection, size);
- return NULL;
+ return -1;
}
extra_space = wl_message_size_extra(message);
@@ -587,7 +575,7 @@ wl_connection_demarshal(struct wl_connection *connection,
sizeof closure->buffer, size + extra_space);
errno = ENOMEM;
wl_connection_consume(connection, size);
- return NULL;
+ return -1;
}
closure->message = message;
@@ -740,14 +728,14 @@ wl_connection_demarshal(struct wl_connection *connection,
wl_connection_consume(connection, size);
- return closure;
+ return 0;
err:
closure->count = i;
wl_closure_destroy(closure);
wl_connection_consume(connection, size);
- return NULL;
+ return -1;
}
void
diff --git a/src/wayland-client.c b/src/wayland-client.c
index 794f716..fb69ed8 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -190,29 +190,29 @@ wl_proxy_add_listener(struct wl_proxy *proxy,
WL_EXPORT void
wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...)
{
- struct wl_closure *closure;
+ struct wl_closure closure;
va_list ap;
+ int ret;
va_start(ap, opcode);
- closure = wl_connection_vmarshal(proxy->display->connection,
- &proxy->object, opcode, ap,
- &proxy->object.interface->methods[opcode]);
+ ret = wl_closure_vmarshal(&closure, &proxy->object, opcode, ap,
+ &proxy->object.interface->methods[opcode]);
va_end(ap);
- if (closure == NULL) {
+ if (ret) {
fprintf(stderr, "Error marshalling request\n");
abort();
}
- if (wl_closure_send(closure, proxy->display->connection)) {
+ if (wl_closure_send(&closure, proxy->display->connection)) {
fprintf(stderr, "Error sending request: %m\n");
abort();
}
if (wl_debug)
- wl_closure_print(closure, &proxy->object, true);
+ wl_closure_print(&closure, &proxy->object, true);
- wl_closure_destroy(closure);
+ wl_closure_destroy(&closure);
}
/* Can't do this, there may be more than one instance of an
@@ -465,8 +465,9 @@ handle_event(struct wl_display *display,
uint32_t id, uint32_t opcode, uint32_t size)
{
struct wl_proxy *proxy;
- struct wl_closure *closure;
+ struct wl_closure closure;
const struct wl_message *message;
+ int ret;
proxy = wl_map_lookup(&display->objects, id);
@@ -479,22 +480,22 @@ handle_event(struct wl_display *display,
}
message = &proxy->object.interface->events[opcode];
- closure = wl_connection_demarshal(display->connection,
- size, &display->objects, message);
+ ret = wl_connection_demarshal(display->connection, &closure,
+ size, &display->objects, message);
- if (closure == NULL) {
+ if (ret) {
fprintf(stderr, "Error demarshalling event\n");
abort();
}
if (wl_debug)
- wl_closure_print(closure, &proxy->object, false);
+ wl_closure_print(&closure, &proxy->object, false);
- wl_closure_invoke(closure, &proxy->object,
+ wl_closure_invoke(&closure, &proxy->object,
proxy->object.implementation[opcode],
proxy->user_data);
- wl_closure_destroy(closure);
+ wl_closure_destroy(&closure);
}
WL_EXPORT void
diff --git a/src/wayland-private.h b/src/wayland-private.h
index b843e89..61b07a2 100644
--- a/src/wayland-private.h
+++ b/src/wayland-private.h
@@ -25,6 +25,7 @@
#define WAYLAND_PRIVATE_H
#include <stdarg.h>
+#include <ffi.h>
#include "wayland-util.h"
#define WL_ZOMBIE_OBJECT ((void *) 2)
@@ -69,17 +70,29 @@ int wl_connection_write(struct wl_connection *connection, const void *data, size
int wl_connection_queue(struct wl_connection *connection,
const void *data, size_t count);
-struct wl_closure *
-wl_connection_vmarshal(struct wl_connection *connection,
- struct wl_object *sender,
- uint32_t opcode, va_list ap,
- const struct wl_message *message);
+struct wl_closure {
+ int count;
+ const struct wl_message *message;
+ ffi_type *types[20];
+ ffi_cif cif;
+ void *args[20];
+ uint32_t buffer[256];
+ uint32_t *start;
+};
+
+int
+wl_closure_vmarshal(struct wl_closure *closure,
+ struct wl_object *sender,
+ uint32_t opcode, va_list ap,
+ const struct wl_message *message);
-struct wl_closure *
+int
wl_connection_demarshal(struct wl_connection *connection,
+ struct wl_closure *closure,
uint32_t size,
struct wl_map *objects,
const struct wl_message *message);
+
void
wl_closure_invoke(struct wl_closure *closure,
struct wl_object *target, void (*func)(void), void *data);
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 1fe00a9..94eb308 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -102,54 +102,54 @@ destroy_client(void *data)
WL_EXPORT void
wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...)
{
- struct wl_closure *closure;
+ struct wl_closure closure;
struct wl_object *object = &resource->object;
va_list ap;
+ int ret;
va_start(ap, opcode);
- closure = wl_connection_vmarshal(resource->client->connection,
- object, opcode, ap,
- &object->interface->events[opcode]);
+ ret = wl_closure_vmarshal(&closure, object, opcode, ap,
+ &object->interface->events[opcode]);
va_end(ap);
- if (closure == NULL)
+ if (ret)
return;
- if (wl_closure_send(closure, resource->client->connection))
+ if (wl_closure_send(&closure, resource->client->connection))
wl_event_loop_add_idle(resource->client->display->loop,
destroy_client, resource->client);
if (wl_debug)
- wl_closure_print(closure, object, true);
+ wl_closure_print(&closure, object, true);
- wl_closure_destroy(closure);
+ wl_closure_destroy(&closure);
}
WL_EXPORT void
wl_resource_queue_event(struct wl_resource *resource, uint32_t opcode, ...)
{
- struct wl_closure *closure;
+ struct wl_closure closure;
struct wl_object *object = &resource->object;
va_list ap;
+ int ret;
va_start(ap, opcode);
- closure = wl_connection_vmarshal(resource->client->connection,
- object, opcode, ap,
- &object->interface->events[opcode]);
+ ret = wl_closure_vmarshal(&closure, object, opcode, ap,
+ &object->interface->events[opcode]);
va_end(ap);
- if (closure == NULL)
+ if (ret)
return;
- if (wl_closure_queue(closure, resource->client->connection))
+ if (wl_closure_queue(&closure, resource->client->connection))
wl_event_loop_add_idle(resource->client->display->loop,
destroy_client, resource->client);
if (wl_debug)
- wl_closure_print(closure, object, true);
+ wl_closure_print(&closure, object, true);
- wl_closure_destroy(closure);
+ wl_closure_destroy(&closure);
}
WL_EXPORT void
@@ -187,12 +187,12 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
struct wl_connection *connection = client->connection;
struct wl_resource *resource;
struct wl_object *object;
- struct wl_closure *closure;
+ struct wl_closure closure;
const struct wl_message *message;
uint32_t p[2];
int opcode, size;
uint32_t cmask = 0;
- int len;
+ int len, ret;
if (mask & WL_EVENT_READABLE)
cmask |= WL_CONNECTION_READABLE;
@@ -232,11 +232,11 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
}
message = &object->interface->methods[opcode];
- closure = wl_connection_demarshal(client->connection, size,
- &client->objects, message);
+ ret = wl_connection_demarshal(client->connection, &closure,
+ size, &client->objects, message);
len -= size;
- if (closure == NULL && errno == EINVAL) {
+ if (ret && errno == EINVAL) {
wl_resource_post_error(client->display_resource,
WL_DISPLAY_ERROR_INVALID_METHOD,
"invalid arguments for %s@%d.%s",
@@ -244,18 +244,18 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
object->id,
message->name);
break;
- } else if (closure == NULL && errno == ENOMEM) {
+ } else if (ret && errno == ENOMEM) {
wl_resource_post_no_memory(resource);
break;
}
if (wl_debug)
- wl_closure_print(closure, object, false);
+ wl_closure_print(&closure, object, false);
- wl_closure_invoke(closure, object,
+ wl_closure_invoke(&closure, object,
object->implementation[opcode], client);
- wl_closure_destroy(closure);
+ wl_closure_destroy(&closure);
if (client->error)
break;