[njs] Stream: introduced "stream" property.

Dmitry Volyntsev xeioex at nginx.com
Mon Mar 1 17:16:56 UTC 2021


details:   https://hg.nginx.org/njs/rev/da49b292dcef
branches:  
changeset: 1615:da49b292dcef
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Feb 26 17:45:56 2021 +0000
description:
Stream: introduced "stream" property.

Is an alias to $status variable.

diffstat:

 nginx/ngx_js.c               |  21 +++++++++++++++++++++
 nginx/ngx_js.h               |   2 ++
 nginx/ngx_stream_js_module.c |  10 ++++++++++
 3 files changed, 33 insertions(+), 0 deletions(-)

diffs (63 lines):

diff -r a83de0fce29f -r da49b292dcef nginx/ngx_js.c
--- a/nginx/ngx_js.c	Mon Mar 01 17:15:44 2021 +0000
+++ b/nginx/ngx_js.c	Fri Feb 26 17:45:56 2021 +0000
@@ -186,6 +186,27 @@ ngx_js_ext_string(njs_vm_t *vm, njs_obje
 
 
 njs_int_t
+ngx_js_ext_uint(njs_vm_t *vm, njs_object_prop_t *prop, njs_value_t *value,
+    njs_value_t *setval, njs_value_t *retval)
+{
+    char        *p;
+    ngx_uint_t   field;
+
+    p = njs_vm_external(vm, value);
+    if (p == NULL) {
+        njs_value_undefined_set(retval);
+        return NJS_DECLINED;
+    }
+
+    field = *(ngx_uint_t *) (p + njs_vm_prop_magic32(prop));
+
+    njs_value_number_set(retval, field);
+
+    return NJS_OK;
+}
+
+
+njs_int_t
 ngx_js_ext_constant(njs_vm_t *vm, njs_object_prop_t *prop,
     njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {
diff -r a83de0fce29f -r da49b292dcef nginx/ngx_js.h
--- a/nginx/ngx_js.h	Mon Mar 01 17:15:44 2021 +0000
+++ b/nginx/ngx_js.h	Fri Feb 26 17:45:56 2021 +0000
@@ -57,6 +57,8 @@ njs_int_t ngx_js_ext_log(njs_vm_t *vm, n
 
 njs_int_t ngx_js_ext_string(njs_vm_t *vm, njs_object_prop_t *prop,
     njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
+njs_int_t ngx_js_ext_uint(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
 njs_int_t ngx_js_ext_constant(njs_vm_t *vm, njs_object_prop_t *prop,
     njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
 njs_int_t ngx_js_ext_boolean(njs_vm_t *vm, njs_object_prop_t *prop,
diff -r a83de0fce29f -r da49b292dcef nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c	Mon Mar 01 17:15:44 2021 +0000
+++ b/nginx/ngx_stream_js_module.c	Fri Feb 26 17:45:56 2021 +0000
@@ -226,6 +226,16 @@ static njs_external_t  ngx_stream_js_ext
 
     {
         .flags = NJS_EXTERN_PROPERTY,
+        .name.string = njs_str("status"),
+        .enumerable = 1,
+        .u.property = {
+            .handler = ngx_js_ext_uint,
+            .magic32 = offsetof(ngx_stream_session_t, status),
+        }
+    },
+
+    {
+        .flags = NJS_EXTERN_PROPERTY,
         .name.string = njs_str("remoteAddress"),
         .enumerable = 1,
         .u.property = {


More information about the nginx-devel mailing list