Skip to content

Commit 8aca0ad

Browse files
committed
initial refactor commit.
1 parent a3a050b commit 8aca0ad

File tree

74 files changed

+9390
-6267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+9390
-6267
lines changed

DEV_NOTES.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
**DO NOT EDIT THIS REPO DIRECTLY, CODE ARE AUTOMATICALLY GENERATED FROM TEMPLATES**
2+
3+
# Install
4+
5+
There are some quirks when compiling the refactored stream module.
6+
7+
You will need NGINX 1.13.x for it to work as we targeted the refactor toward
8+
that version only. The [1.13.x branch](https://github.com/openresty/openresty/tree/1.13.x)
9+
of OpenResty should serve this well.
10+
11+
You need to turn off FFI when compiling (for the time being) as not all FFI functions got
12+
their respective guard.
13+
14+
Here is what I use for compiling:
15+
16+
```shell
17+
./configure --prefix=/home/datong/openresty-stream-build \
18+
--with-stream --with-stream_ssl_module
19+
--add-module=/home/datong/orinc/stream-lua-nginx-module
20+
-j4 --with-cc-opt='-DNGX_LUA_NO_FFI_API' --with-debug
21+
```
22+
23+
# Status
24+
The project can run simple "Hello, World" without any problem or Valgrind warnings.
25+
26+
I have also tested timer and variable support and they appears to work as well.
27+
28+
The only feature that has not been ported is the cosocket API due to it's
29+
complexity. This does makes the module somewhat useless as input from user can not be read by
30+
Lua programs right now. I will spend some time to sort this out shortly.
31+
32+
I will spend some time debugging and get the test suite running next.

config

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,19 +302,19 @@ fi
302302
ngx_addon_name=ngx_stream_lua_module
303303
STREAM_MODULES="$STREAM_MODULES ngx_stream_lua_module"
304304
NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
305+
$ngx_addon_dir/src/ngx_stream_lua_api.c \
306+
$ngx_addon_dir/src/ngx_stream_lua_request.c \
305307
$ngx_addon_dir/src/ngx_stream_lua_module.c \
306308
$ngx_addon_dir/src/ngx_stream_lua_directive.c \
307309
$ngx_addon_dir/src/ngx_stream_lua_lex.c \
308310
$ngx_addon_dir/src/ngx_stream_lua_contentby.c \
309311
$ngx_addon_dir/src/ngx_stream_lua_util.c \
310312
$ngx_addon_dir/src/ngx_stream_lua_cache.c \
311313
$ngx_addon_dir/src/ngx_stream_lua_clfactory.c \
312-
$ngx_addon_dir/src/ngx_stream_lua_socket_tcp.c \
313314
$ngx_addon_dir/src/ngx_stream_lua_exception.c \
314315
$ngx_addon_dir/src/ngx_stream_lua_pcrefix.c \
315316
$ngx_addon_dir/src/ngx_stream_lua_uthread.c \
316317
$ngx_addon_dir/src/ngx_stream_lua_coroutine.c \
317-
$ngx_addon_dir/src/ngx_stream_lua_semaphore.c \
318318
$ngx_addon_dir/src/ngx_stream_lua_output.c \
319319
$ngx_addon_dir/src/ngx_stream_lua_consts.c \
320320
$ngx_addon_dir/src/ngx_stream_lua_log.c \
@@ -328,29 +328,27 @@ NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
328328
$ngx_addon_dir/src/ngx_stream_lua_script.c \
329329
$ngx_addon_dir/src/ngx_stream_lua_shdict.c \
330330
$ngx_addon_dir/src/ngx_stream_lua_variable.c \
331-
$ngx_addon_dir/src/ngx_stream_lua_socket_udp.c \
332331
$ngx_addon_dir/src/ngx_stream_lua_timer.c \
333332
$ngx_addon_dir/src/ngx_stream_lua_config.c \
334333
$ngx_addon_dir/src/ngx_stream_lua_worker.c \
335334
$ngx_addon_dir/src/ngx_stream_lua_misc.c \
336335
$ngx_addon_dir/src/ngx_stream_lua_initby.c \
337-
$ngx_addon_dir/src/ngx_stream_lua_args.c \
338336
$ngx_addon_dir/src/ngx_stream_lua_initworkerby.c \
339337
"
340338

341339
NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
342340
$ngx_addon_dir/src/ddebug.h \
341+
$ngx_addon_dir/src/api/ngx_stream_lua_api.h \
342+
$ngx_addon_dir/src/ngx_stream_lua_request.h \
343343
$ngx_addon_dir/src/ngx_stream_lua_common.h \
344344
$ngx_addon_dir/src/ngx_stream_lua_lex.h \
345345
$ngx_addon_dir/src/ngx_stream_lua_contentby.h \
346346
$ngx_addon_dir/src/ngx_stream_lua_util.h \
347347
$ngx_addon_dir/src/ngx_stream_lua_cache.h \
348348
$ngx_addon_dir/src/ngx_stream_lua_clfactory.h \
349-
$ngx_addon_dir/src/ngx_stream_lua_socket_tcp.h \
350349
$ngx_addon_dir/src/ngx_stream_lua_pcrefix.h \
351350
$ngx_addon_dir/src/ngx_stream_lua_uthread.h \
352351
$ngx_addon_dir/src/ngx_stream_lua_coroutine.h \
353-
$ngx_addon_dir/src/ngx_stream_lua_semaphore.h \
354352
$ngx_addon_dir/src/ngx_stream_lua_output.h \
355353
$ngx_addon_dir/src/ngx_stream_lua_consts.h \
356354
$ngx_addon_dir/src/ngx_stream_lua_log.h \
@@ -364,14 +362,12 @@ NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
364362
$ngx_addon_dir/src/ngx_stream_lua_script.h \
365363
$ngx_addon_dir/src/ngx_stream_lua_shdict.h \
366364
$ngx_addon_dir/src/ngx_stream_lua_variable.h \
367-
$ngx_addon_dir/src/ngx_stream_lua_socket_udp.h \
368365
$ngx_addon_dir/src/ngx_stream_lua_timer.h \
369366
$ngx_addon_dir/src/ngx_stream_lua_config.h \
370367
$ngx_addon_dir/src/api/ngx_stream_lua_api.h \
371368
$ngx_addon_dir/src/ngx_stream_lua_worker.h \
372369
$ngx_addon_dir/src/ngx_stream_lua_misc.h \
373370
$ngx_addon_dir/src/ngx_stream_lua_initby.h \
374-
$ngx_addon_dir/src/ngx_stream_lua_args.h \
375371
$ngx_addon_dir/src/ngx_stream_lua_initworkerby.h \
376372
"
377373

src/api/ngx_stream_lua_api.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <nginx.h>
1212
#include <ngx_core.h>
13-
#include <ngx_stream.h>
13+
#include <ngx_http.h>
1414

1515
#include <lua.h>
1616
#include <stdint.h>
@@ -19,7 +19,7 @@
1919
/* Public API for other Nginx modules */
2020

2121

22-
#define ngx_stream_lua_version 10001
22+
#define ngx_stream_lua_version 10009
2323

2424

2525
typedef struct {
@@ -36,12 +36,20 @@ typedef struct {
3636

3737
lua_State *ngx_stream_lua_get_global_state(ngx_conf_t *cf);
3838

39-
ngx_stream_session_t *ngx_stream_lua_get_session(lua_State *L);
39+
ngx_stream_lua_request_t *ngx_stream_lua_get_request(lua_State *L);
4040

41-
ngx_int_t ngx_stream_lua_add_package_preload(ngx_conf_t *cf,
42-
const char *package, lua_CFunction func);
41+
ngx_int_t ngx_stream_lua_add_package_preload(ngx_conf_t *cf, const char *package,
42+
lua_CFunction func);
43+
44+
ngx_int_t ngx_stream_lua_shared_dict_get(ngx_shm_zone_t *shm_zone,
45+
u_char *key_data, size_t key_len, ngx_stream_lua_value_t *value);
4346

4447
ngx_shm_zone_t *ngx_stream_lua_find_zone(u_char *name_data, size_t name_len);
4548

49+
ngx_shm_zone_t *ngx_stream_lua_shared_memory_add(ngx_conf_t *cf, ngx_str_t *name,
50+
size_t size, void *tag);
51+
4652

4753
#endif /* _NGX_STREAM_LUA_API_H_INCLUDED_ */
54+
55+
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

src/ddebug.h

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,82 @@
44
*/
55

66

7-
#ifndef DDEBUG_H
8-
#define DDEBUG_H
7+
#ifndef _DDEBUG_H_INCLUDED_
8+
#define _DDEBUG_H_INCLUDED_
99

1010

1111
#include <ngx_config.h>
12+
#include <nginx.h>
1213
#include <ngx_core.h>
1314

1415

1516
#if defined(DDEBUG) && (DDEBUG)
1617

1718
# if (NGX_HAVE_VARIADIC_MACROS)
1819

19-
# define dd(...) fprintf(stderr, "stream lua *** %s: ", __func__); \
20+
# define dd(...) fprintf(stderr, "lua *** %s: ", __func__); \
2021
fprintf(stderr, __VA_ARGS__); \
2122
fprintf(stderr, " at %s line %d.\n", __FILE__, __LINE__)
2223

2324
# else
2425

2526
#include <stdarg.h>
2627
#include <stdio.h>
28+
2729
#include <stdarg.h>
2830

2931
static ngx_inline void
30-
dd(const char * fmt, ...)
31-
{
32+
dd(const char *fmt, ...) {
3233
}
3334

3435
# endif
3536

3637
#else
3738

3839
# if (NGX_HAVE_VARIADIC_MACROS)
40+
3941
# define dd(...)
42+
4043
# else
4144

4245
#include <stdarg.h>
4346

4447
static ngx_inline void
45-
dd(const char * fmt, ...)
46-
{
48+
dd(const char *fmt, ...) {
4749
}
4850

4951
# endif
5052

5153
#endif
5254

53-
#endif /* DDEBUG_H */
55+
#if defined(DDEBUG) && (DDEBUG)
56+
57+
#define dd_check_read_event_handler(r) \
58+
dd("r->read_event_handler = %s", \
59+
r->read_event_handler == ngx_http_block_reading ? \
60+
"ngx_http_block_reading" : \
61+
r->read_event_handler == ngx_http_test_reading ? \
62+
"ngx_http_test_reading" : \
63+
r->read_event_handler == ngx_http_request_empty_handler ? \
64+
"ngx_http_request_empty_handler" : "UNKNOWN")
65+
66+
#define dd_check_write_event_handler(r) \
67+
dd("r->write_event_handler = %s", \
68+
r->write_event_handler == ngx_http_handler ? \
69+
"ngx_http_handler" : \
70+
r->write_event_handler == ngx_http_core_run_phases ? \
71+
"ngx_http_core_run_phases" : \
72+
r->write_event_handler == ngx_http_request_empty_handler ? \
73+
"ngx_http_request_empty_handler" : "UNKNOWN")
74+
75+
#else
76+
77+
#define dd_check_read_event_handler(r)
78+
#define dd_check_write_event_handler(r)
79+
80+
#endif
81+
82+
83+
#endif /* _DDEBUG_H_INCLUDED_ */
84+
85+
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

0 commit comments

Comments
 (0)