diff options
author | Andrei Belov <defan@nginx.com> | 2019-03-01 18:30:09 +0300 |
---|---|---|
committer | Andrei Belov <defan@nginx.com> | 2019-03-01 18:30:09 +0300 |
commit | 3c3720cba7154bc168cbd00c74817626bb53e140 (patch) | |
tree | da1500f7c6bd5e90ecf45299b6f4b19a29d521cd /src/nxt_unit.c | |
parent | 315a864c27aa27a48c013c4a1ef67a099ffea894 (diff) | |
parent | df02b03824065389c73213b19736140442cf63bc (diff) | |
download | unit-3c3720cba7154bc168cbd00c74817626bb53e140.tar.gz unit-3c3720cba7154bc168cbd00c74817626bb53e140.tar.bz2 |
Merged with the default branch.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_unit.c | 95 |
1 files changed, 28 insertions, 67 deletions
diff --git a/src/nxt_unit.c b/src/nxt_unit.c index 24e51075..6339aec5 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -541,6 +541,8 @@ nxt_unit_process_msg(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id, memcpy(&fd, CMSG_DATA(cm), sizeof(int)); } + nxt_queue_init(&incoming_buf); + if (nxt_slow_path(buf_size < sizeof(nxt_port_msg_t))) { nxt_unit_warn(ctx, "message too small (%d bytes)", (int) buf_size); goto fail; @@ -570,8 +572,6 @@ nxt_unit_process_msg(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id, } if (port_msg->mmap) { - nxt_queue_init(&incoming_buf); - if (nxt_unit_mmap_read(ctx, &recv_msg, &incoming_buf) != NXT_UNIT_OK) { goto fail; } @@ -890,59 +890,6 @@ nxt_unit_field_hash(const char *name, size_t name_length) void -nxt_unit_split_host(char *host, uint32_t host_length, - char **name, uint32_t *name_length, char **port, uint32_t *port_length) -{ - char *cpos; - - static char default_host[] = "localhost"; - static char default_port[] = "80"; - - if (nxt_slow_path(host == NULL || host_length == 0)) { - *name = default_host; - *name_length = nxt_length(default_host); - - *port = default_port; - *port_length = nxt_length(default_port); - - return; - } - - cpos = memchr(host, ':', host_length); - - if (nxt_slow_path(cpos == NULL)) { - *name = host; - *name_length = host_length; - - *port = default_port; - *port_length = nxt_length(default_port); - - return; - } - - if (nxt_slow_path(cpos == host)) { - *name = default_host; - *name_length = nxt_length(default_host); - - } else { - *name = host; - *name_length = cpos - host; - } - - cpos++; - - if (nxt_slow_path(host + host_length == cpos)) { - *port = default_port; - *port_length = nxt_length(default_port); - - } else { - *port = cpos; - *port_length = host_length - (cpos - host); - } -} - - -void nxt_unit_request_group_dup_fields(nxt_unit_request_info_t *req) { uint32_t i, j; @@ -957,10 +904,6 @@ nxt_unit_request_group_dup_fields(nxt_unit_request_info_t *req) for (i = 0; i < r->fields_count; i++) { switch (fields[i].hash) { - case NXT_UNIT_HASH_HOST: - r->host_field = i; - break; - case NXT_UNIT_HASH_CONTENT_LENGTH: r->content_length_field = i; break; @@ -1104,8 +1047,11 @@ nxt_unit_response_realloc(nxt_unit_request_info_t *req, + max_fields_count * sizeof(nxt_unit_field_t) + max_fields_size; + nxt_unit_req_debug(req, "realloc %"PRIu32"", buf_size); + buf = nxt_unit_response_buf_alloc(req, buf_size); if (nxt_slow_path(buf == NULL)) { + nxt_unit_req_warn(req, "realloc: new buf allocation failed"); return NXT_UNIT_ERROR; } @@ -1120,23 +1066,29 @@ nxt_unit_response_realloc(nxt_unit_request_info_t *req, f = resp->fields; for (i = 0; i < req->response->fields_count; i++) { - src = req->request->fields + i; + src = req->response->fields + i; if (nxt_slow_path(src->skip != 0)) { continue; } - if (nxt_slow_path(src->name_length + src->value_length + if (nxt_slow_path(src->name_length + src->value_length + 2 > (uint32_t) (buf->end - p))) { + nxt_unit_req_warn(req, "realloc: not enough space for field" + " #%"PRIu32" (%p), (%"PRIu32" + %"PRIu32") required", + i, src, src->name_length, src->value_length); + goto fail; } nxt_unit_sptr_set(&f->name, p); p = nxt_cpymem(p, nxt_unit_sptr_get(&src->name), src->name_length); + *p++ = '\0'; nxt_unit_sptr_set(&f->value, p); p = nxt_cpymem(p, nxt_unit_sptr_get(&src->value), src->value_length); + *p++ = '\0'; f->hash = src->hash; f->skip = 0; @@ -1151,6 +1103,10 @@ nxt_unit_response_realloc(nxt_unit_request_info_t *req, if (nxt_slow_path(req->response->piggyback_content_length > (uint32_t) (buf->end - p))) { + nxt_unit_req_warn(req, "realloc: not enought space for content" + " #%"PRIu32", %"PRIu32" required", + i, req->response->piggyback_content_length); + goto fail; } @@ -1219,7 +1175,7 @@ nxt_unit_response_add_field(nxt_unit_request_info_t *req, buf = req->response_buf; - if (nxt_slow_path(name_length + value_length + if (nxt_slow_path(name_length + value_length + 2 > (uint32_t) (buf->end - buf->free))) { nxt_unit_req_warn(req, "add_field: response buffer overflow"); @@ -1236,9 +1192,11 @@ nxt_unit_response_add_field(nxt_unit_request_info_t *req, nxt_unit_sptr_set(&f->name, buf->free); buf->free = nxt_cpymem(buf->free, name, name_length); + *buf->free++ = '\0'; nxt_unit_sptr_set(&f->value, buf->free); buf->free = nxt_cpymem(buf->free, value, value_length); + *buf->free++ = '\0'; f->hash = nxt_unit_field_hash(name, name_length); f->skip = 0; @@ -1622,7 +1580,9 @@ nxt_unit_buf_next(nxt_unit_buf_t *buf) lnk = &mmap_buf->link; - if (lnk == nxt_queue_last(&req_impl->incoming_buf)) { + if (lnk == nxt_queue_last(&req_impl->incoming_buf) + || lnk == nxt_queue_last(&req_impl->outgoing_buf)) + { return NULL; } @@ -1767,6 +1727,9 @@ nxt_unit_response_write_cb(nxt_unit_request_info_t *req, } while (!read_info->eof) { + nxt_unit_req_debug(req, "write_cb, alloc %"PRIu32"", + read_info->buf_size); + buf = nxt_unit_response_buf_alloc(req, nxt_min(read_info->buf_size, PORT_MMAP_DATA_SIZE)); if (nxt_slow_path(buf == NULL)) { @@ -2506,14 +2469,12 @@ nxt_unit_mmap_read(nxt_unit_ctx_t *ctx, nxt_unit_recv_msg_t *recv_msg, b->buf.end = b->buf.start + size; b->hdr = hdr; - nxt_unit_debug(ctx, "#%"PRIu32": mmap_read: [%p,%d] %d->%d,(%d,%d,%d)\n" - "%.*s", + nxt_unit_debug(ctx, "#%"PRIu32": mmap_read: [%p,%d] %d->%d,(%d,%d,%d)", recv_msg->port_msg.stream, start, (int) size, (int) hdr->src_pid, (int) hdr->dst_pid, (int) hdr->id, (int) mmap_msg->chunk_id, - (int) mmap_msg->size, - (int) size, (char *) start); + (int) mmap_msg->size); } pthread_mutex_unlock(&process->incoming.mutex); |