コード例 #1
0
/* TYPICALLY CALLED FROM ANOTHER THREAD */
void
hio_output_stream_write(HioOutputStream *stream,
                        HrtBuffer       *locked_buffer)
{
    g_return_if_fail(hrt_buffer_is_locked(locked_buffer));

    if (hrt_buffer_get_length(locked_buffer) == 0)
        return;

    if (hio_output_stream_is_closed(stream))
        return;

    g_mutex_lock(stream->buffers_lock);
    /* note, we still want to buffer stuff if fd == -1 since that just
     * means we aren't being asked to write yet. But on error, discard
     * anything that gets written.
     */
    if (g_atomic_int_get(&stream->errored) == 0) {
        /* we could set stream->errored right here after we just
         * checked we haven't. However in that case, the
         * drop_all_buffers() just after we set stream->errored will
         * have to block for buffers_lock and only then drop them, so
         * it should drop this one we're pushing.
         */
        hrt_buffer_ref(locked_buffer);
        g_queue_push_tail(&stream->buffers,
                          locked_buffer);
    }
    g_mutex_unlock(stream->buffers_lock);

    /* add write watcher if necessary. */
    check_write_watcher(stream);
}
コード例 #2
0
void
hio_response_http_set_header(HioResponseHttp *http,
                             HrtBuffer       *name,
                             HrtBuffer       *value)
{
    g_return_if_fail(hrt_buffer_is_locked(name));
    g_return_if_fail(hrt_buffer_is_locked(value));

    g_mutex_lock(http->headers_lock);

    if (http->headers_sent) {
        g_mutex_unlock(http->headers_lock);
        hrt_message("Attempt to set http header after we already sent the headers, ignoring");
        return;
    }

    /* FIXME overwrite a previous duplicate header if any */
    http->headers = g_slist_prepend(http->headers,
                                    header_new(name, value));
    g_mutex_unlock(http->headers_lock);
}