static ngx_int_t ngx_http_upstream_get_zeromq_peer(ngx_peer_connection_t *pc, void *data) { ngx_http_upstream_zeromq_peer_data_t *zp = data; ngx_int_t rc; if (zp->recv.endpoint != zp->send.endpoint) { pc->data = &zp->recv; rc = ngx_zeromq_connect(pc); pc->data = data; if (rc != NGX_OK) { return rc; } zp->recv.connection.data = zp->request; } pc->data = &zp->send; rc = ngx_zeromq_connect(pc); pc->data = data; if (rc != NGX_OK) { return rc; } zp->send.connection.data = zp->request; if (zp->recv.endpoint != zp->send.endpoint) { zp->send.recv = zp->recv.recv; zp->recv.send = zp->send.send; } if (zp->recv.endpoint->rand && zp->headers) { ngx_zeromq_headers_set_http(zp->headers->buf, zp->recv.endpoint); } return NGX_DONE; }
ngx_chain_t * ngx_zeromq_headers_add_http(ngx_chain_t *in, ngx_zeromq_endpoint_t *zep, ngx_pool_t *pool) { ngx_chain_t *cl; ngx_buf_t *b; size_t len; len = sizeof("X-ZeroMQ-RespondTo: ") - 1 + 2 * (sizeof(CRLF) - 1) + zep->type->name.len + zep->addr.len; if (zep->rand) { len += sizeof("65535") - 1; } b = ngx_create_temp_buf(pool, len); if (b == NULL) { return NGX_CHAIN_ERROR; } cl = ngx_alloc_chain_link(pool); if (cl == NULL) { return NGX_CHAIN_ERROR; } cl->buf = b; cl->next = in->next; in->next = cl; if (!zep->rand) { ngx_zeromq_headers_set_http(b, zep); } in->buf->last -= sizeof(CRLF) - 1; return cl; }