vtest: refactor vtest_server_run_renderer

Refactor command dispatching to a separate function,
vtest_client_dispatch_commands.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-By: Gert Wollny <gert.wollny@collabora.com>
Reviewed-By: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Chia-I Wu 5 years ago
parent 3b8bf6b3eb
commit b88a34d5d3
  1. 71
      vtest/vtest_server.c

@ -102,6 +102,7 @@ static void vtest_server_run_renderer(struct vtest_client *client);
static void vtest_server_wait_for_socket_accept(void);
static void vtest_server_tidy_fds(void);
static void vtest_server_close_socket(void);
static int vtest_client_dispatch_commands(struct vtest_client *client);
int main(int argc, char **argv)
@ -367,6 +368,33 @@ static void vtest_server_wait_for_socket_accept(void)
client->input.read = vtest_block_read;
}
static void vtest_server_run_renderer(struct vtest_client *client)
{
int err, ret;
do {
ret = vtest_wait_for_fd_read(client->in_fd);
if (ret < 0) {
err = 1;
break;
}
err = vtest_client_dispatch_commands(client);
if (err) {
break;
}
} while (1);
fprintf(stderr, "socket failed (%d) - closing renderer\n", err);
if (client->context) {
vtest_destroy_context(client->context);
client->context = NULL;
}
vtest_cleanup_renderer();
}
typedef int (*vtest_cmd_fptr_t)(uint32_t);
static const vtest_cmd_fptr_t vtest_commands[] = {
@ -387,29 +415,20 @@ static const vtest_cmd_fptr_t vtest_commands[] = {
vtest_transfer_put2,
};
static void vtest_server_run_renderer(struct vtest_client *client)
static int vtest_client_dispatch_commands(struct vtest_client *client)
{
int err, ret;
int ret;
uint32_t header[VTEST_HDR_SIZE];
do {
ret = vtest_wait_for_fd_read(client->in_fd);
if (ret < 0) {
err = 1;
break;
}
ret = client->input.read(&client->input, &header, sizeof(header));
if (ret < 0 || (size_t)ret < sizeof(header)) {
err = 2;
break;
return 2;
}
if (!client->context) {
/* The first command MUST be VCMD_CREATE_RENDERER */
if (header[1] != VCMD_CREATE_RENDERER) {
err = 3;
break;
return 3;
}
ret = vtest_init_renderer(server.ctx_flags, server.render_device);
@ -418,30 +437,27 @@ static void vtest_server_run_renderer(struct vtest_client *client)
header[0], &client->context);
}
if (ret < 0) {
err = 4;
break;
return 4;
}
printf("%s: vtest initialized.\n", __func__);
vtest_set_current_context(client->context);
vtest_poll();
continue;
return 0;
}
vtest_poll();
if (header[1] <= 0 || header[1] >= ARRAY_SIZE(vtest_commands)) {
err = 5;
break;
return 5;
}
if (vtest_commands[header[1]] == NULL) {
err = 6;
break;
return 6;
}
ret = vtest_commands[header[1]](header[0]);
if (ret < 0) {
err = 7;
break;
return 7;
}
/* GL draws are fenced, while possible fence creations are too */
@ -449,16 +465,7 @@ static void vtest_server_run_renderer(struct vtest_client *client)
header[1] == VCMD_RESOURCE_CREATE2)
vtest_renderer_create_fence();
} while (1);
fprintf(stderr, "socket failed (%d) - closing renderer\n", err);
if (client->context) {
vtest_destroy_context(client->context);
client->context = NULL;
}
vtest_cleanup_renderer();
return 0;
}
static void vtest_server_tidy_fds(void)

Loading…
Cancel
Save