예제 #1
0
static ngx_chain_t *
ngx_zeromq_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
{
    ngx_zeromq_connection_t  *zc;
    ngx_event_t              *wev;
    ngx_chain_t              *cl;
    ngx_buf_t                *b;
    void                     *zmq;
    ssize_t                   n;

    wev = c->write;

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

    if (c->write->handler != ngx_zeromq_event_handler) {
        zc->handler = c->write->handler;

        c->write->handler = ngx_zeromq_event_handler;
        c->read->handler = ngx_zeromq_event_handler;
    }

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

        b = cl->buf;

        if (ngx_buf_special(cl->buf)) {
            continue;
        }

        n = ngx_zeromq_send_part(zmq, wev, b->pos, b->last - b->pos,
                                 cl->next ? ZMQ_SNDMORE : 0);
        if (n < 0) {
            if (n == NGX_AGAIN) {
                return cl;
            }

            return (ngx_chain_t *) n;
        }

        b->pos = b->last;

        c->sent += n;
    }

    zc->request_sent = 1;

    return NULL;
}
예제 #2
0
static ngx_chain_t *
ngx_zeromq_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
{
    ngx_event_t  *wev;
    ngx_chain_t  *cl;
    ngx_buf_t    *b;
    ngx_int_t     rc;
    void         *zmq;
    ssize_t       n;

    wev = c->write;

    zmq = ngx_zeromq_get_socket(c);

    rc = ngx_zeromq_ready(zmq, wev, "zmq_send", ZMQ_POLLOUT);

    if (rc == NGX_ERROR) {
        return NGX_CHAIN_ERROR;

    } else if (rc == NGX_AGAIN) {
        return in;
    }

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

        b = cl->buf;

        if (ngx_buf_special(cl->buf)) {
            continue;
        }

        n = ngx_zeromq_send_part(zmq, wev, b->pos, b->last - b->pos,
                                 cl->next ? ZMQ_SNDMORE : 0);
        if (n < 0) {
            return (ngx_chain_t *) n;
        }

        b->pos = b->last;

        c->sent += n;
    }

    return NULL;
}