コード例 #1
0
ファイル: multipart-test.c プロジェクト: skion/libsoup
static void
multipart_next_part_cb (GObject *source, GAsyncResult *res, gpointer data)
{
    GMainLoop *loop = (GMainLoop*)data;
    GError *error = NULL;
    GInputStream *in;
    gsize read_size = READ_BUFFER_SIZE;

    g_assert (SOUP_MULTIPART_INPUT_STREAM (source) == multipart);

    in = soup_multipart_input_stream_next_part_finish (multipart, res, &error);

    if (error) {
        debug_printf (1, "  failed next part: %s\n", error->message);
        g_clear_error (&error);
        errors++;

        g_object_unref (multipart);
        g_main_loop_quit (loop);
        return;
    }

    if (!in) {
        if (passes != 4) {
            debug_printf (1, "  expected 4 parts, got %u\n", passes);
            errors++;
        }

        g_object_unref (multipart);
        g_main_loop_quit (loop);
        return;
    }

    check_headers (multipart, passes);

    if (g_object_get_data (G_OBJECT (multipart), "multipart-small-reads"))
        read_size = 4;

    g_input_stream_read_async (in, buffer, read_size,
                               G_PRIORITY_DEFAULT, NULL,
                               multipart_read_cb, data);
}
コード例 #2
0
ファイル: multipart.c プロジェクト: jbastian/restraint
/*
 * Try and read another multipart message. if in is NULL then there are no more
 * messages to read.
 */
static void
next_part_cb (GObject *source, GAsyncResult *async_result, gpointer user_data)
{
    //g_print ("next_part_cb: Enter\n");
    SoupMultipartInputStream *multipart = SOUP_MULTIPART_INPUT_STREAM (source);

    MultiPartData *multipart_data = (MultiPartData *) user_data;

    g_assert (SOUP_MULTIPART_INPUT_STREAM (source) == multipart_data->multipart);

    GInputStream *in = soup_multipart_input_stream_next_part_finish (multipart,
                                                       async_result,
                                                       &multipart_data->error);
    if (!in) {
        g_input_stream_close_async (G_INPUT_STREAM (multipart),
                                    G_PRIORITY_DEFAULT,
                                    multipart_data->cancellable,
                                    close_base_cb,
                                    user_data);
        return;
    }

    // Read the headers here.
    multipart_read_headers (multipart_data);

    multipart_data->buffer = g_string_sized_new(READ_BUFFER_SIZE);

    g_input_stream_read_async (in,
                               buffer,
                               READ_BUFFER_SIZE,
                               G_PRIORITY_DEFAULT,
                               multipart_data->cancellable,
                               read_cb,
                               user_data);
    //g_print ("next_part_cb: Exit\n");
}