Skip to content

Commit 35a8f8f

Browse files
committed
feature update
AIO threads for older nginx version Remove null terminator for request body, base on lens instead
1 parent 455cd51 commit 35a8f8f

File tree

6 files changed

+89
-29
lines changed

6 files changed

+89
-29
lines changed

build_test_resources/cfuntest.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void my_app_simple_get_greeting(ngx_http_c_func_ctx_t *ctx) {
2727
ngx_http_c_func_log_info(ctx, "Calling back and log from my_app_simple_get");
2828

2929
char *rep = "greeting from ngx_http_c_func testing";
30+
// sleep(4); uncomment for testing aio threads
3031
ngx_http_c_func_write_resp(
3132
ctx,
3233
200,
@@ -134,8 +135,8 @@ void my_app_simple_post(ngx_http_c_func_ctx_t *ctx) {
134135
202,
135136
"202 Accepted and Processing",
136137
"text/plain",
137-
ctx->req_body,
138-
strlen(ctx->req_body)
138+
ctx->req_body,
139+
ctx->req_body_len
139140
);
140141
}
141142
}

config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ngx_feature_incs="#include <ngx_http_c_func_module.h>"
2424
ngx_feature_path=
2525
ngx_feature_libs=
2626
# ngx_feature_exit_if_not_found=yes
27-
ngx_feature_test="int ngx_http_c_func_module_current_version_=ngx_http_c_func_module_version_10;"
27+
ngx_feature_test="int ngx_http_c_func_module_current_version_=ngx_http_c_func_module_version_11;"
2828
. auto/feature
2929

3030
if [ $ngx_found != yes ]; then

src/ngx_http_c_func_module.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static ngx_int_t ngx_http_c_func_get_resp_var(ngx_http_request_t *r, ngx_http_va
134134
static void ngx_http_c_func_set_resp_var_with_r(ngx_http_request_t *r, ngx_http_c_func_ctx_t *ctx, const char* resp_content);
135135
static void ngx_http_c_func_output_filter(ngx_http_request_t *r);
136136

137-
#if (NGX_THREADS) && (nginx_version > 1013003)
137+
#if (NGX_THREADS)
138138
static void ngx_http_c_func_after_process(ngx_event_t *ev);
139139
static void ngx_http_c_func_process_t_handler(void *data, ngx_log_t *log);
140140
#endif
@@ -524,7 +524,7 @@ ngx_http_c_func_post_configuration(ngx_conf_t *cf) {
524524
#if (nginx_version > 1013003)
525525
h = ngx_array_push(&cmcf->phases[NGX_HTTP_PRECONTENT_PHASE].handlers);
526526
#else /**Access Phase is the only last phase for multi thread**/
527-
h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
527+
h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
528528
#endif
529529
if (h == NULL) {
530530
return NGX_ERROR;
@@ -535,7 +535,7 @@ ngx_http_c_func_post_configuration(ngx_conf_t *cf) {
535535

536536
/*** Default Init for shm with 1M if pool is empty***/
537537
if (mcf != NULL && !mcf->is_cache_defined ) {
538-
ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "%s", "Init Default Share memory with 1k");
538+
ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "%s", "Init Default Share memory with 1M");
539539
ngx_str_t default_size = ngx_string("1M");
540540

541541
ngx_shm_zone_t *shm_zone = ngx_shared_memory_add(cf, &mcf->shm_ctx->name, ngx_parse_size(&default_size), &ngx_http_c_func_module);
@@ -554,7 +554,7 @@ ngx_http_c_func_post_configuration(ngx_conf_t *cf) {
554554
static ngx_int_t
555555
ngx_http_c_func_pre_configuration(ngx_conf_t *cf) {
556556

557-
#ifndef ngx_http_c_func_module_version_10
557+
#ifndef ngx_http_c_func_module_version_11
558558
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "the latest ngx_http_c_func_module.h not found in the c header path, \
559559
please copy latest ngx_http_c_func_module.h to your /usr/include or /usr/local/include or relavent header search path \
560560
with read and write permission.");
@@ -578,11 +578,7 @@ ngx_http_c_func_module_init(ngx_cycle_t *cycle) {
578578
cscfp = cmcf->servers.elts;
579579

580580
#if (NGX_THREADS)
581-
#if(nginx_version > 1013003)
582581
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, " enabled aio threads for c-function module ");
583-
#else
584-
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, " upgrade to nginx 1.13.4 and above to enable aio threads for c-function module ");
585-
#endif
586582
#endif
587583

588584
for (s = 0; s < cmcf->servers.nelts; s++) {
@@ -895,7 +891,7 @@ ngx_http_c_func_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) {
895891
return NGX_CONF_OK;
896892
}
897893

898-
#if (NGX_THREADS) && (nginx_version > 1013003)
894+
#if (NGX_THREADS)
899895
static void
900896
ngx_http_c_func_process_t_handler(void *data, ngx_log_t *log)
901897
{
@@ -1040,7 +1036,7 @@ ngx_http_c_func_precontent_handler(ngx_http_request_t *r) {
10401036
for (cl = r->request_body->bufs; cl; cl = cl->next) {
10411037
p = ngx_copy(p, cl->buf->pos, cl->buf->last - cl->buf->pos);
10421038
}
1043-
buf[len] = '\0';
1039+
// buf[len] = '\0';
10441040

10451041
} else {
10461042
b = r->request_body->bufs->buf;
@@ -1049,7 +1045,7 @@ ngx_http_c_func_precontent_handler(ngx_http_request_t *r) {
10491045
}
10501046
buf = ngx_palloc(r->pool, (len + 1) );
10511047
ngx_memcpy(buf, b->pos, len);
1052-
buf[len] = '\0';
1048+
// buf[len] = '\0';
10531049
}
10541050
/************End REading ****************/
10551051

@@ -1082,7 +1078,7 @@ ngx_http_c_func_precontent_handler(ngx_http_request_t *r) {
10821078
new_ctx->req_body_len = 0;
10831079
}
10841080

1085-
#if (NGX_THREADS) && (nginx_version > 1013003)
1081+
#if (NGX_THREADS)
10861082
ngx_thread_pool_t *tp;
10871083
ngx_http_core_loc_conf_t *clcf;
10881084

@@ -1114,11 +1110,8 @@ ngx_http_c_func_precontent_handler(ngx_http_request_t *r) {
11141110
return NGX_DECLINED;
11151111
}
11161112
ngx_http_c_func_output_filter(r);
1117-
#if (nginx_version > 1013003)
1113+
11181114
return NGX_DONE;
1119-
#else
1120-
return NGX_OK;
1121-
#endif
11221115
} /* ngx_http_c_func_precontent_handler */
11231116

11241117

src/ngx_http_c_func_module.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <stdlib.h>
4141
#include <stdint.h>
4242

43-
#define ngx_http_c_func_module_version_10 10
43+
#define ngx_http_c_func_module_version_11 11
4444

4545

4646
#define ngx_http_c_func_content_type_plaintext "text/plain"
@@ -54,8 +54,8 @@
5454
typedef struct {
5555
char *req_args; // Uri Args
5656
u_char *req_body; // Request Body
57+
size_t req_body_len; // length of body
5758
void *shared_mem;
58-
size_t req_body_len; // length of body, including terminating \0
5959

6060
/* internal */
6161
void* __r__;

t/libcfuntest.so

216 Bytes
Binary file not shown.

t/sanity.t

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ __DATA__
1414

1515
=== TEST 1: Set C_FUNC_TEST_1
1616
--- config
17-
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
17+
ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
1818
location = /testCFunGreeting {
1919
ngx_http_c_func_call "my_app_simple_get_greeting";
2020
}
@@ -26,9 +26,10 @@ Content-Type: text/plain
2626
--- response_body_like eval
2727
qr/greeting from ngx_http_c_func testing$/
2828

29+
2930
=== TEST 2: Set C_FUNC_TEST_ARGS
3031
--- config
31-
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
32+
ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
3233
location = /testCFunARGS {
3334
ngx_http_c_func_call "my_app_simple_get_args";
3435
}
@@ -43,7 +44,7 @@ qr/greeting=hello_nginx\?id=129310923$/
4344

4445
=== TEST 3: Set C_FUNC_TEST_POST_NONE
4546
--- config
46-
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
47+
ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
4748
location = /testCFunPOSTBody {
4849
ngx_http_c_func_call "my_app_simple_post";
4950
}
@@ -59,7 +60,7 @@ qr/\s/
5960

6061
=== TEST 4: Set C_FUNC_TEST_GET_TOKEN
6162
--- config
62-
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
63+
ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
6364
location = /testCFunCVerifyToken {
6465
ngx_http_c_func_call "my_app_simple_get_token_args";
6566
}
@@ -74,7 +75,7 @@ qr/QVNKS0pDQVNLTEpDS0xBU0pXbGtlandrbGplIGpka2FqbGthc2tsZGtqbHNrICBrZGpha2xzZGphc
7475

7576
=== TEST 5: Set C_FUNC_TEST_GET_ERROR_RESP
7677
--- config
77-
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
78+
ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
7879
location = /testCFUNCERRORRESP {
7980
ngx_http_c_func_call "my_app_simple_get_no_resp";
8081
}
@@ -87,7 +88,7 @@ Content-Type: text/html
8788

8889
=== TEST 6: Set C_FUNC_TEST_GET_CALLOC_FROM_POOL
8990
--- config
90-
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
91+
ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
9192
location = /testCFUNCCallocFromPool {
9293
ngx_http_c_func_call "my_app_simple_get_calloc_from_pool";
9394
}
@@ -102,7 +103,7 @@ qr/This is the message calloc from pool$/
102103

103104
=== TEST 7: Set C_FUNC_TEST_POST_BODY
104105
--- config
105-
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
106+
ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
106107
location = /testCFunPOSTBody {
107108
ngx_http_c_func_call "my_app_simple_post";
108109
}
@@ -118,7 +119,7 @@ qr/greeting=enjoy-http-c-function-testing$/
118119

119120
=== TEST 8: Set C_FUNC_TEST_CACHE
120121
--- config
121-
ngx_http_c_func_link_lib "/home/dispatch/testMap/c-lib/nginx-c-function/t/libcfuntest.so";
122+
ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
122123
location = /testCFunGetCache {
123124
ngx_http_c_func_call "my_app_simple_get_cache";
124125
}
@@ -129,3 +130,68 @@ POST /testCFunGetCache
129130
Content-Type: text/plain
130131
--- response_body_like eval
131132
qr/This is cache value$/
133+
134+
135+
=== TEST 9: Set C_FUNC_TEST_VARIABLE
136+
--- config
137+
ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
138+
location = /testCFunGreeting {
139+
ngx_http_c_func_call "my_app_simple_get_greeting" respTo=myRespVariable;
140+
return 200 $myRespVariable;
141+
}
142+
--- request
143+
GET /testCFunGreeting
144+
--- error_code: 200
145+
--- response_headers
146+
Content-Type: text/plain
147+
--- response_body_like eval
148+
qr/greeting from ngx_http_c_func testing$/
149+
150+
151+
=== TEST 10: Set C_FUNC_TEST_ARGS_AND_VARIABLE
152+
--- config
153+
ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
154+
location = /testCFunARGS {
155+
ngx_http_c_func_call "my_app_simple_get_args" respTo=simpleRespVariable;
156+
return 200 $simpleRespVariable;
157+
}
158+
--- request
159+
GET /testCFunARGS?greeting=hello_nginx?id=129310923
160+
--- error_code: 200
161+
--- response_headers
162+
Content-Type: text/plain
163+
--- response_body_like eval
164+
qr/greeting=hello_nginx\?id=129310923$/
165+
166+
167+
=== TEST 11: Set C_FUNC_AIO_THREADS_TEST_ARGS_AND_VARIABLE
168+
--- config
169+
aio threads;
170+
ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
171+
location = /testCFunARGS {
172+
ngx_http_c_func_call "my_app_simple_get_args" respTo=simpleRespVariable;
173+
return 200 $simpleRespVariable;
174+
}
175+
--- request
176+
GET /testCFunARGS?greeting=hello_nginx?id=129310923
177+
--- error_code: 200
178+
--- response_headers
179+
Content-Type: text/plain
180+
--- response_body_like eval
181+
qr/greeting=hello_nginx\?id=129310923$/
182+
183+
184+
=== TEST 12: Set C_FUNC_AIO_THREADS_TEST
185+
--- config
186+
aio threads;
187+
ngx_http_c_func_link_lib "/home/taymindis/github/nginx-c-function/t/libcfuntest.so";
188+
location = /testCFunGreeting {
189+
ngx_http_c_func_call "my_app_simple_get_greeting";
190+
}
191+
--- request
192+
GET /testCFunGreeting
193+
--- error_code: 200
194+
--- response_headers
195+
Content-Type: text/plain
196+
--- response_body_like eval
197+
qr/greeting from ngx_http_c_func testing$/

0 commit comments

Comments
 (0)