Exemplo n.º 1
0
int cb_td_flush(void *data, size_t bytes, void *out_context,
                struct flb_config *config)
{
    int n;
    char buf[1024];
    ssize_t w_bytes;
    size_t out_len;
    char *request;
    struct flb_out_td_config *ctx = out_context;

    request = td_http_request(data, bytes, &out_len, ctx, config);
    w_bytes = write(ctx->fd, request, out_len);
    if (w_bytes < 0) {
        perror("write");
        /* FIXME: handle connection timeout */
        if (errno == EBADF) {
            close(ctx->fd);
            ctx->fd = flb_net_tcp_connect(out_td_plugin.host,
                                          out_td_plugin.port);
        }
    }
    free(request);

    n = read(ctx->fd, buf, 4096);
    buf[n] = '\0';

    flb_debug("[TD] API server response:\n%s", buf);
    return w_bytes;
}
Exemplo n.º 2
0
int cb_td_flush(void *data, size_t bytes, void *out_context,
                struct flb_config *config)
{
    int n;
    int ret;
    int bytes_out;
    char *pack;
    size_t bytes_sent;
    char buf[1024];
    size_t len;
    char *request;
    struct flb_out_td_config *ctx = out_context;

    /* Convert format */
    pack = td_format(data, bytes, &bytes_out);
    if (!pack) {
        return -1;
    }

    request = td_http_request(pack, bytes_out, &len, ctx, config);
    ret = flb_io_net_write(ctx->u, request, len, &bytes_sent);
    if (ret == -1) {
        perror("write");
    }
    free(request);
    free(pack);

    n = flb_io_net_read(ctx->u, buf, sizeof(buf) - 1);
    if (n > 0) {
        buf[n] = '\0';
        flb_debug("[TD] API server response:\n%s", buf);
    }

    return bytes_sent;
}