Ejemplo n.º 1
0
static ssize_t
ngx_zeromq_recv_chain(ngx_connection_t *c, ngx_chain_t *cl)
{
    ngx_event_t  *rev;
    ngx_buf_t    *b;
    ngx_int_t     rc;
    void         *zmq;
    ssize_t       n, size;

    rev = c->read;

    if (rev->eof) {
        ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "zmq_recv: - eom:1");
        return 0;
    }

    zmq = ngx_zeromq_get_socket(c);

    rc = ngx_zeromq_ready(zmq, rev, "zmq_recv", ZMQ_POLLIN);
    if (rc < 0) {
        return rc;
    }

    size = 0;

    for (; cl; cl = cl->next) {

        b = cl->buf;

        n = ngx_zeromq_recv_part(zmq, rev, b->last, b->end - b->last);
        if (n < 0) {
            return n;
        }

        b->last += n;
        b->end = b->last;

        size += n;

        if (rev->eof) {
            break;
        }
    }

    return size;
}
Ejemplo n.º 2
0
static ssize_t
ngx_zeromq_recv(ngx_connection_t *c, u_char *buf, size_t size)
{
    ngx_http_request_t  *r;
    ngx_event_t         *rev;
    ngx_int_t            rc;
    void                *zmq;
    ssize_t              n;

    rev = c->read;

    if (rev->eof) {
        ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "zmq_recv: - eom:1");
        return 0;
    }

    zmq = ngx_zeromq_get_socket(c);

    rc = ngx_zeromq_ready(zmq, rev, "zmq_recv", ZMQ_POLLIN);
    if (rc < 0) {
        return rc;
    }

    n = ngx_zeromq_recv_part(zmq, rev, buf, size);
    if (n < 0) {
        return n;
    }

    /*
     * This *really* shouldn't be here, but we need to cheat nginx into
     * thinking that the whole buffer space was used, otherwise it will
     * try to read into remaining part of this buffer, which could lead
     * to message part not fitting in.
     */

    r = c->data;
    if (buf == r->upstream->buffer.start) {
        r->upstream->buffer.end += size;
    }

    return n;
}
Ejemplo n.º 3
0
ngx_zeromq_recv_chain(ngx_connection_t *c, ngx_chain_t *cl)
#endif
{
    ngx_zeromq_connection_t  *zc;
    ngx_event_t              *rev;
    ngx_buf_t                *b;
    void                     *zmq;
    ssize_t                   n, size;

    rev = c->read;

    if (rev->eof) {
        ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "zmq_recv: - eom:1");
        return 0;
    }

    zc = (ngx_zeromq_connection_t *) c;
    zmq = zc->recv->socket;

    size = 0;

    for (; cl; cl = cl->next) {

        b = cl->buf;

        n = ngx_zeromq_recv_part(zmq, rev, b->last, b->end - b->last);
        if (n < 0) {
            return n;
        }

        b->last += n;
        b->end = b->last;

        size += n;

        if (rev->eof) {
            break;
        }
    }

    return size;
}