diff options
author | Max Romanov <max.romanov@nginx.com> | 2018-08-06 17:27:33 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2018-08-06 17:27:33 +0300 |
commit | 1bb22d1e922c87d3c86c67bdce626767ee48fb5c (patch) | |
tree | 6e067a82b309c3a0d0f592f037f26d886a7f8c13 /src/nxt_application.h | |
parent | b6ce2da65c9c5229d744b2d964623b2d0f731ee9 (diff) | |
download | unit-1bb22d1e922c87d3c86c67bdce626767ee48fb5c.tar.gz unit-1bb22d1e922c87d3c86c67bdce626767ee48fb5c.tar.bz2 |
Unit application library.
Library now used in all language modules.
Old 'nxt_app_*' code removed.
See src/test/nxt_unit_app_test.c for usage sample.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_application.h | 162 |
1 files changed, 9 insertions, 153 deletions
diff --git a/src/nxt_application.h b/src/nxt_application.h index 1fca5dff..35346655 100644 --- a/src/nxt_application.h +++ b/src/nxt_application.h @@ -11,6 +11,8 @@ #include <nxt_conf.h> +#include <nxt_unit_typedefs.h> + typedef enum { NXT_APP_PYTHON, @@ -23,7 +25,6 @@ typedef enum { } nxt_app_type_t; -typedef struct nxt_app_module_s nxt_application_module_t; typedef struct nxt_app_module_s nxt_app_module_t; @@ -31,7 +32,7 @@ typedef struct { nxt_app_type_t type; u_char *version; char *file; - nxt_application_module_t *module; + nxt_app_module_t *module; } nxt_app_lang_module_t; @@ -129,6 +130,7 @@ typedef struct { typedef struct nxt_app_parse_ctx_s nxt_app_parse_ctx_t; + struct nxt_app_parse_ctx_s { nxt_app_request_t r; nxt_http_request_t *request; @@ -143,75 +145,6 @@ struct nxt_app_parse_ctx_s { nxt_int_t nxt_app_http_req_done(nxt_task_t *task, nxt_app_parse_ctx_t *ctx); -typedef struct nxt_app_wmsg_s nxt_app_wmsg_t; -typedef struct nxt_app_rmsg_s nxt_app_rmsg_t; - -struct nxt_app_wmsg_s { - nxt_port_t *port; /* where prepared buf will be sent */ - nxt_buf_t *write; - nxt_buf_t **buf; - uint32_t stream; -}; - - -struct nxt_app_rmsg_s { - nxt_buf_t *buf; /* current buffer to read */ -}; - - -nxt_inline u_char * -nxt_app_msg_write_length(u_char *dst, size_t length); - -/* TODO asynchronous mmap buffer assignment */ -NXT_EXPORT u_char *nxt_app_msg_write_get_buf(nxt_task_t *task, - nxt_app_wmsg_t *msg, size_t size); - -NXT_EXPORT nxt_int_t nxt_app_msg_write(nxt_task_t *task, nxt_app_wmsg_t *msg, - u_char *c, size_t size); - -NXT_EXPORT nxt_int_t nxt_app_msg_write_prefixed_upcase(nxt_task_t *task, - nxt_app_wmsg_t *msg, const nxt_str_t *prefix, u_char *c, size_t size); - -nxt_inline nxt_int_t -nxt_app_msg_write_nvp_(nxt_task_t *task, nxt_app_wmsg_t *msg, - u_char *n, size_t nsize, u_char *v, size_t vsize); - - -#define nxt_app_msg_write_const(task, msg, c) \ - nxt_app_msg_write((task), (msg), (u_char *) (c), nxt_length(c)) - -#define nxt_app_msg_write_str(task, msg, str) \ - nxt_app_msg_write((task), (msg), (str)->start, (str)->length) - -#define nxt_app_msg_write_cstr(task, msg, c) \ - nxt_app_msg_write((task), (msg), (c), nxt_strlen(c)) - -#define nxt_app_msg_write_nvp(task, msg, n, v) \ - nxt_app_msg_write_nvp_((task), (msg), (u_char *) (n), nxt_length(n), \ - (v)->start, (v)->length) - -nxt_inline nxt_int_t nxt_app_msg_write_size(nxt_task_t *task, - nxt_app_wmsg_t *msg, size_t size); - -NXT_EXPORT nxt_int_t nxt_app_msg_flush(nxt_task_t *task, nxt_app_wmsg_t *msg, - nxt_bool_t last); - -NXT_EXPORT nxt_int_t nxt_app_msg_write_raw(nxt_task_t *task, - nxt_app_wmsg_t *msg, const u_char *c, size_t size); - -NXT_EXPORT nxt_int_t nxt_app_msg_read_str(nxt_task_t *task, nxt_app_rmsg_t *msg, - nxt_str_t *str); - -NXT_EXPORT size_t nxt_app_msg_read_raw(nxt_task_t *task, - nxt_app_rmsg_t *msg, void *buf, size_t size); - -NXT_EXPORT nxt_int_t nxt_app_msg_read_nvp(nxt_task_t *task, - nxt_app_rmsg_t *rmsg, nxt_str_t *n, nxt_str_t *v); - -NXT_EXPORT nxt_int_t nxt_app_msg_read_size(nxt_task_t *task, - nxt_app_rmsg_t *rmsg, size_t *size); - - struct nxt_app_module_s { size_t compat_length; uint32_t *compat; @@ -221,94 +154,17 @@ struct nxt_app_module_s { nxt_int_t (*init)(nxt_task_t *task, nxt_common_app_conf_t *conf); - nxt_int_t (*run)(nxt_task_t *task, - nxt_app_rmsg_t *rmsg, - nxt_app_wmsg_t *wmsg); - void (*atexit)(nxt_task_t *task); }; -nxt_int_t nxt_app_http_read_body(nxt_app_request_t *r, u_char *data, - size_t len); -nxt_int_t nxt_app_write(nxt_app_request_t *r, const u_char *data, size_t len); - -nxt_inline u_char * -nxt_app_msg_write_length(u_char *dst, size_t length) -{ - if (length < 128) { - *dst = length; - dst++; - - } else { - dst[0] = 0x80U | (length >> 24); - dst[1] = 0xFFU & (length >> 16); - dst[2] = 0xFFU & (length >> 8); - dst[3] = 0xFFU & length; - dst += 4; - } - - return dst; -} - - -nxt_inline nxt_int_t -nxt_app_msg_write_nvp_(nxt_task_t *task, nxt_app_wmsg_t *msg, - u_char *n, size_t nsize, u_char *v, size_t vsize) -{ - nxt_int_t rc; - - rc = nxt_app_msg_write(task, msg, n, nsize); - if (nxt_slow_path(rc != NXT_OK)) { - return rc; - } - - return nxt_app_msg_write(task, msg, v, vsize); -} - - -nxt_inline nxt_int_t -nxt_app_msg_write_size(nxt_task_t *task, nxt_app_wmsg_t *msg, size_t size) -{ - u_char *dst; - size_t dst_length; - - dst_length = size < 128 ? 1 : 4; - - dst = nxt_app_msg_write_get_buf(task, msg, dst_length); - if (nxt_slow_path(dst == NULL)) { - return NXT_ERROR; - } - - nxt_app_msg_write_length(dst, size); - - return NXT_OK; -} - - -nxt_inline u_char * -nxt_app_msg_read_length(u_char *src, size_t *length) -{ - if (src[0] < 128) { - *length = src[0]; - src++; - - } else { - *length = ((src[0] & 0x7FU) << 24) - + ( src[1] << 16) - + ( src[2] << 8) - + src[3]; - src += 4; - } - - return src; -} - - nxt_app_lang_module_t *nxt_app_lang_module(nxt_runtime_t *rt, nxt_str_t *name); nxt_app_type_t nxt_app_parse_type(u_char *p, size_t length); -NXT_EXPORT extern nxt_str_t nxt_server; -extern nxt_application_module_t nxt_go_module; +NXT_EXPORT extern nxt_str_t nxt_server; +extern nxt_app_module_t nxt_go_module; + +NXT_EXPORT nxt_int_t nxt_unit_default_init(nxt_task_t *task, + nxt_unit_init_t *init); #endif /* _NXT_APPLICATION_H_INCLIDED_ */ |