diff options
author | Hans de Goede <hdegoede@redhat.com> | 2010-10-27 16:20:56 +0200 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2010-10-27 16:33:46 +0200 |
commit | 530761b2391963c5319ec429391288d3cf77456c (patch) | |
tree | 0f16b7414a11b6327302efcd55eadb57eed3f77f | |
parent | 947694e4cf562090cf0f8910a31cb394f032e3f8 (diff) | |
download | vd_agent-530761b2391963c5319ec429391288d3cf77456c.tar.gz vd_agent-530761b2391963c5319ec429391288d3cf77456c.tar.xz vd_agent-530761b2391963c5319ec429391288d3cf77456c.zip |
udscs: sync up callback disconnect handling
-rw-r--r-- | udscs.c | 5 | ||||
-rw-r--r-- | udscs.h | 8 | ||||
-rw-r--r-- | vdagent.c | 3 | ||||
-rw-r--r-- | vdagentd.c | 9 |
4 files changed, 10 insertions, 15 deletions
@@ -467,10 +467,9 @@ static void udscs_read_complete(struct udscs_connection **connp) } if (conn->read_callback) { - if (conn->read_callback(conn, &conn->header, conn->data.buf) == -1) { - udscs_destroy_connection(connp); + conn->read_callback(connp, &conn->header, conn->data.buf); + if (!*connp) /* Was the connection disconnected by the callback ? */ return; - } } free(conn->data.buf); @@ -39,11 +39,9 @@ struct udscs_message_header { server is accepted. */ typedef void (*udscs_connect_callback)(struct udscs_connection *conn); /* Callbacks with this type will be called when a complete message has been - received. Sometimes the callback may want to close the connection, in this - case do *not* call udscs_destroy_connection from the callback. The desire - to close the connection can be indicated be returning -1 from the callback, - in other cases return 0. */ -typedef int (*udscs_read_callback)(struct udscs_connection *conn, + received. The callback may call udscs_destroy_connection, in which case + *connp must be made NULL (which udscs_destroy_connection takes care of) */ +typedef void (*udscs_read_callback)(struct udscs_connection **connp, struct udscs_message_header *header, const uint8_t *data); /* Callback type for udscs_server_for_all_clients. Clients can be disconnected from this callback just like with a read callback. */ @@ -35,7 +35,7 @@ static int verbose = 0; static struct vdagent_x11 *x11 = NULL; -int daemon_read_complete(struct udscs_connection *conn, +void daemon_read_complete(struct udscs_connection **connp, struct udscs_message_header *header, const uint8_t *data) { switch (header->type) { @@ -60,7 +60,6 @@ int daemon_read_complete(struct udscs_connection *conn, fprintf(stderr, "Unknown message from vdagentd type: %d\n", header->type); } - return 0; } static void usage(FILE *fp) @@ -305,7 +305,7 @@ void client_disconnect(struct udscs_connection *conn) } } -int client_read_complete(struct udscs_connection *conn, +void client_read_complete(struct udscs_connection **connp, struct udscs_message_header *header, const uint8_t *data) { switch (header->type) { @@ -316,7 +316,8 @@ int client_read_complete(struct udscs_connection *conn, if (header->size != sizeof(*res)) { fprintf(stderr, "guest xorg resolution message has wrong size, disconnecting client\n"); - return -1; + udscs_destroy_connection(connp); + return; } /* Now that we know the xorg resolution setup the uinput device */ @@ -338,14 +339,12 @@ int client_read_complete(struct udscs_connection *conn, case VDAGENTD_CLIPBOARD_REQUEST: case VDAGENTD_CLIPBOARD_DATA: case VDAGENTD_CLIPBOARD_RELEASE: - do_client_clipboard(conn, header, data); + do_client_clipboard(*connp, header, data); break; default: fprintf(stderr, "unknown message from vdagent client: %u, ignoring\n", header->type); } - - return 0; } /* main */ |