Пример #1
0
/**
 * Function to send messages (Msg) to riemann.
 *
 * Acquires the host lock, disconnects on errors.
 */
static int riemann_send(struct riemann_host *host, Msg const *msg) /* {{{ */
{
    int status = 0;
    pthread_mutex_lock (&host->lock);

    status = riemann_send_msg(host, msg);
    if (status != 0) {
        riemann_disconnect (host);
        pthread_mutex_unlock (&host->lock);
        return status;
    }

    /*
     * For TCP we need to receive message acknowledgemenent.
     */
    if (host->use_tcp)
    {
        status = riemann_recv_ack(host);

        if (status != 0)
        {
            riemann_disconnect (host);
            pthread_mutex_unlock (&host->lock);
            return status;
        }
    }

    pthread_mutex_unlock (&host->lock);
    return 0;
} /* }}} int riemann_send */
Пример #2
0
/*
 * Always call while holding host->lock !
 */
static int riemann_batch_flush_nolock (cdtime_t timeout,
                                       struct riemann_host *host)
{
    cdtime_t    now;
    int         status = 0;

    if (timeout > 0) {
        now = cdtime ();
        if ((host->batch_init + timeout) > now)
            return status;
    }
    riemann_send_msg(host, host->batch_msg);
    riemann_msg_protobuf_free(host->batch_msg);

	if (host->use_tcp && ((status = riemann_recv_ack(host)) != 0))
        riemann_disconnect (host);

    host->batch_init = cdtime();
    host->batch_msg = NULL;
    return status;
}