예제 #1
0
static void
test_stream_with_error(OutputTestFixture *fixture,
                       const void        *data)
{
    HioOutputStream *stream;

    g_assert(fixture->chain_task == NULL);

    close(fixture->read_fd); /* should error the writes */

    stream = hio_output_stream_new(fixture->stream_tasks[0]);
    hio_output_stream_set_fd(stream, fixture->write_fd);

    hrt_task_add_immediate(fixture->write_tasks[0],
                           on_write_stream_task,
                           write_task_data_new(stream, fixture->stream_descs),
                           write_task_data_free);

    /* run main loop to collect the tasks */
    g_main_loop_run(fixture->loop);

    /* if the stream is zero-length we'll never try to write and never get an error */
    g_assert(fixture->stream_descs->length == 0 ||
             hio_output_stream_got_error(stream));
    g_assert(hio_output_stream_is_done(stream));
    g_assert(hio_output_stream_is_closed(stream));

    g_object_unref(stream);

    /* so we don't close it again in teardown */
    fixture->read_fd = -1;
}
예제 #2
0
static void
test_stream_with_initial_error(OutputTestFixture *fixture,
                               const void        *data)
{
    HioOutputStream *stream;

    g_assert(fixture->chain_task == NULL);

    /* error before we even set an fd on it */
    stream = hio_output_stream_new(fixture->stream_tasks[0]);
    hio_output_stream_error(stream);

    hrt_task_add_immediate(fixture->write_tasks[0],
                           on_write_stream_task,
                           write_task_data_new(stream, fixture->stream_descs),
                           write_task_data_free);

    /* run main loop to collect the tasks */
    g_main_loop_run(fixture->loop);

    g_assert(hio_output_stream_got_error(stream));
    g_assert(hio_output_stream_is_done(stream));
    g_assert(hio_output_stream_is_closed(stream));

    g_object_unref(stream);
}
예제 #3
0
static void
test_stream(OutputTestFixture *fixture,
            const void        *data)
{
    HioOutputStream *stream;

    g_assert(fixture->chain_task == NULL);

    stream = hio_output_stream_new(fixture->stream_tasks[0]);
    hio_output_stream_set_fd(stream, fixture->write_fd);

    hrt_task_add_immediate(fixture->write_tasks[0],
                           on_write_stream_task,
                           write_task_data_new(stream, fixture->stream_descs),
                           write_task_data_free);

    read_and_verify_stream(fixture->read_fd, fixture->stream_descs);

    /* run main loop to collect the task */
    g_main_loop_run(fixture->loop);

    g_assert(!hio_output_stream_got_error(stream));
    g_assert(hio_output_stream_is_done(stream));
    g_assert(hio_output_stream_is_closed(stream));

    g_object_unref(stream);
}
예제 #4
0
/* CALLED FROM ANY THREAD */
gboolean
hio_output_stream_is_done(HioOutputStream *stream)
{
    gboolean done;

    g_mutex_lock(stream->buffers_lock);
    done = hio_output_stream_is_closed(stream) &&
        (g_queue_get_length(&stream->buffers) == 0 ||
         hio_output_stream_got_error(stream));
    g_mutex_unlock(stream->buffers_lock);

    return done;
}