diff options
author | Max Romanov <max.romanov@nginx.com> | 2017-12-06 12:16:02 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2017-12-06 12:16:02 +0300 |
commit | d14c0774c7e6f372dfebcfcafdcac718b7e28789 (patch) | |
tree | 6111a740fb2d1898b0375a8f65235d3f319b160a /src/go/unit/nxt_go_port.c | |
parent | 0db4d2531648796a3447a409f05bd82bcc91ff9f (diff) | |
download | unit-d14c0774c7e6f372dfebcfcafdcac718b7e28789.tar.gz unit-d14c0774c7e6f372dfebcfcafdcac718b7e28789.tar.bz2 |
Go: removing request registry.
Passing unsafe.Pointers (void *) from Go to C is complicated by an attempt
to make such pointers less unsafe.
A straightforward optimization is to replace 'unsafe.Pointer' with 'uintptr'
(thanks to Xin Huang for the idea: https://stackoverflow.com/a/44826533 ).
As a result, request registry with mutex is gone.
Diffstat (limited to 'src/go/unit/nxt_go_port.c')
-rw-r--r-- | src/go/unit/nxt_go_port.c | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/go/unit/nxt_go_port.c b/src/go/unit/nxt_go_port.c index 8ea9a5ca..cbf12ab2 100644 --- a/src/go/unit/nxt_go_port.c +++ b/src/go/unit/nxt_go_port.c @@ -27,16 +27,15 @@ nxt_go_data_handler(nxt_port_msg_t *port_msg, size_t size) nxt_go_request_t r; nxt_app_request_header_t *h; - r = nxt_go_find_request(port_msg->stream); - if (r != 0) { - return r; - } + ctx = malloc(sizeof(nxt_go_run_ctx_t) + size); + + memcpy(ctx + 1, port_msg, size); + port_msg = (nxt_port_msg_t *) (ctx + 1); - ctx = malloc(sizeof(nxt_go_run_ctx_t)); nxt_go_ctx_init(ctx, port_msg, size - sizeof(nxt_port_msg_t)); r = (nxt_go_request_t)(ctx); - h = &ctx->r.header; + h = &ctx->request.header; nxt_go_ctx_read_str(ctx, &h->method); nxt_go_ctx_read_str(ctx, &h->target); @@ -58,18 +57,20 @@ nxt_go_data_handler(nxt_port_msg_t *port_msg, size_t size) h->path = h->target; } - nxt_go_new_request(r, port_msg->stream, nxt_go_str(&h->method), - nxt_go_str(&h->target)); + ctx->go_request = nxt_go_new_request(r, port_msg->stream, + nxt_go_str(&h->method), + nxt_go_str(&h->target)); nxt_go_ctx_read_str(ctx, &h->version); - nxt_go_request_set_proto(r, nxt_go_str(&h->version), + nxt_go_request_set_proto(ctx->go_request, nxt_go_str(&h->version), h->version.start[5] - '0', h->version.start[7] - '0'); - nxt_go_ctx_read_str(ctx, &ctx->r.remote); - if (ctx->r.remote.start != NULL) { - nxt_go_request_set_remote_addr(r, nxt_go_str(&ctx->r.remote)); + nxt_go_ctx_read_str(ctx, &ctx->request.remote); + if (ctx->request.remote.start != NULL) { + nxt_go_request_set_remote_addr(ctx->go_request, + nxt_go_str(&ctx->request.remote)); } nxt_go_ctx_read_str(ctx, &h->host); @@ -78,7 +79,7 @@ nxt_go_data_handler(nxt_port_msg_t *port_msg, size_t size) nxt_go_ctx_read_str(ctx, &h->content_length); if (h->host.start != NULL) { - nxt_go_request_set_host(r, nxt_go_str(&h->host)); + nxt_go_request_set_host(ctx->go_request, nxt_go_str(&h->host)); } nxt_go_ctx_read_size(ctx, &s); @@ -92,21 +93,23 @@ nxt_go_data_handler(nxt_port_msg_t *port_msg, size_t size) } rc = nxt_go_ctx_read_str(ctx, &v); - nxt_go_request_add_header(r, nxt_go_str(&n), nxt_go_str(&v)); + nxt_go_request_add_header(ctx->go_request, nxt_go_str(&n), + nxt_go_str(&v)); } while(1); nxt_go_ctx_read_size(ctx, &s); - ctx->r.body.preread_size = s; + ctx->request.body.preread_size = s; if (h->parsed_content_length > 0) { - nxt_go_request_set_content_length(r, h->parsed_content_length); + nxt_go_request_set_content_length(ctx->go_request, + h->parsed_content_length); } - if (ctx->r.body.preread_size < h->parsed_content_length) { - nxt_go_request_create_channel(r); + if (ctx->request.body.preread_size < h->parsed_content_length) { + nxt_go_warn("preread_size < content_length"); } - return r; + return ctx->go_request; } nxt_go_request_t |