static gpointer test_helper_server(gpointer opaque)
{
    struct GVncTest *data = opaque;
    GSocketListener *server;
    GSocketConnection *client;
    GIOStream *ios;
    GInputStream *is;
    GOutputStream *os;

    server = g_socket_listener_new();

    data->port = g_socket_listener_add_any_inet_port(server, NULL, NULL);
    g_mutex_unlock(&data->lock);

    client = g_socket_listener_accept(server, NULL, NULL, NULL);

    ios = G_IO_STREAM(client);
    is = g_io_stream_get_input_stream(ios);
    os = g_io_stream_get_output_stream(ios);

    guint8 greeting[] = {
        'R', 'F', 'B', ' ',
        '0', '0', '3', '.',
        '0', '0', '8', '\n',
    };

    /* Greeting */
    test_send_bytes(os, greeting, G_N_ELEMENTS(greeting));
    test_recv_bytes(is, greeting, G_N_ELEMENTS(greeting));

    /* N auth */
    test_send_u8(os, 1);
    /* auth == none */
    test_send_u8(os, 1);
    test_recv_u8(is, 1);

    /* auth result */
    test_send_u32(os, 0);

    data->test_func(is, os);

    g_mutex_lock(&data->clock);
    while (!data->quit) {
        g_cond_wait(&data->cond, &data->clock);
    }

    g_object_unref(client);
}
static gpointer test_helper_server(gpointer opaque)
{
    struct GVncTest *data = opaque;
    GSocketListener *server;
    GSocketConnection *client;
    GIOStream *ios;
    GInputStream *is;
    GOutputStream *os;

    server = g_socket_listener_new();

    data->port = g_socket_listener_add_any_inet_port(server, NULL, NULL);
    g_mutex_unlock(&data->lock);

    client = g_socket_listener_accept(server, NULL, NULL, NULL);

    ios = G_IO_STREAM(client);
    is = g_io_stream_get_input_stream(ios);
    os = g_io_stream_get_output_stream(ios);

    guint8 greeting[] = {
        'R', 'F', 'B', ' ',
        '0', '0', '3', '.',
        '0', '0', '8', '\n',
    };

     
    test_send_bytes(os, greeting, G_N_ELEMENTS(greeting));
    test_recv_bytes(is, greeting, G_N_ELEMENTS(greeting));

     
    test_send_u8(os, 1);
     
    test_send_u8(os, 1);
    test_recv_u8(is, 1);

     
    test_send_u32(os, 0);

    data->test_func(is, os);

    g_mutex_lock(&data->clock);
    while (!data->quit) {
        g_cond_wait(&data->cond, &data->clock);
    }

    g_object_unref(client);
}