Example #1
0
static void
header_free(Header *header)
{
    hrt_buffer_unref(header->name);
    hrt_buffer_unref(header->value);
    g_slice_free(Header, header);
}
Example #2
0
static void
write_stream(HioOutputStream  *stream,
             const StreamDesc *desc)
{
    StreamGenerator generator;
    gsize remaining;

    stream_generator_init(&generator, desc->seed);
    remaining = desc->length;

    while (remaining > 0) {
        char buf[48];
        gsize count;
        HrtBuffer *buffer;

        count = MIN(G_N_ELEMENTS(buf), remaining);
        stream_generator_generate(&generator,
                                  &buf[0],
                                  count);

        buffer = hrt_buffer_new(HRT_BUFFER_ENCODING_UTF8,
                                &allocator,
                                NULL, NULL);
        hrt_buffer_append_ascii(buffer, &buf[0], count);
        hrt_buffer_lock(buffer);

        hio_output_stream_write(stream, buffer);

        hrt_buffer_unref(buffer);

        g_assert(count <= remaining);
        remaining -= count;
    }
}
Example #3
0
static void
write_to_header(HioResponseHttp *http,
                const char      *s)
{
    HrtBuffer *buffer;

    buffer = hrt_buffer_new_static_utf8_locked(s);
    hio_output_stream_write(http->header_stream,
                            buffer);
    hrt_buffer_unref(buffer);
}
Example #4
0
/* IN OUR TASK THREAD */
static void
ensure_current_buffer(HioOutputStream *stream,
                      HrtBuffer       *completed)
{
    HRT_ASSERT_IN_TASK_THREAD(stream->task);

    if (stream->current_buffer == NULL || completed) {
        g_mutex_lock(stream->buffers_lock);

        if (completed != NULL) {
            HrtBuffer *old;

            g_assert(completed == stream->current_buffer);

            old = g_queue_pop_head(&stream->buffers);
            g_assert(old == completed);
            hrt_buffer_unref(completed);
            stream->current_buffer = NULL;
        }

        /* Just peek, to leave the current buffer in stream->buffers
         * so the write thread can see if there's anything to write,
         * since only our task thread can look at
         * stream->current_buffer
         */

        stream->current_buffer =
            g_queue_peek_head(&stream->buffers);
        if (stream->current_buffer != NULL) {
            stream->current_buffer_remaining =
                hrt_buffer_get_write_size(stream->current_buffer);
        }

        g_mutex_unlock(stream->buffers_lock);
    }

    /* Be sure to NULL current_buffer if an error has occurred so we
     * don't try to write it. An async drop_all_buffers() will have been
     * queued as well but we want to do it earlier if we get here
     * since someone has asked for current_buffer to be up-to-date.
     */
    if (g_atomic_int_get(&stream->errored) > 0) {
        drop_all_buffers(stream);
    }
}
Example #5
0
/* IN OUR TASK THREAD */
static void
drop_all_buffers(HioOutputStream *stream)
{
    HrtBuffer *buffer;

    HRT_ASSERT_IN_TASK_THREAD(stream->task);

    /* we're about to free current_buffer as the head of the queue
     */
    stream->current_buffer = NULL;

    g_mutex_lock(stream->buffers_lock);
    while ((buffer = g_queue_pop_head(&stream->buffers)) != NULL) {
        hrt_buffer_unref(buffer);
    }
    g_mutex_unlock(stream->buffers_lock);

    check_write_watcher(stream);

    notify_if_done(stream);
}
Example #6
0
/* request has been sufficiently parsed (usually, it has all headers
 * but not the body if any) to go ahead and start working.
 */
void
hwf_request_container_execute(HwfRequestContainer *request,
                              HrtTask             *request_task)
{
    HioResponseHttp *response;
    HrtBuffer *buffer;

    hrt_debug("Executing request %p in task %p", request, request_task);

    response = hio_request_http_get_response(HIO_REQUEST_HTTP(request));

    hio_response_http_send_headers(response);

    buffer = hrt_buffer_new_static_utf8_locked("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"><TITLE>HELLO WORLD</TITLE><P>This is a web page.</P>");

    hio_response_http_write(response, buffer);

    hrt_buffer_unref(buffer);

    hio_response_http_close(response);
}