Welcome! Log In Create A New Profile

Advanced

[njs] Interactive shell: initial support of posted events.

Dmitry Volyntsev
December 28, 2018 04:48AM
details: https://hg.nginx.org/njs/rev/f08c5fc1dea8
branches:
changeset: 703:f08c5fc1dea8
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Fri Dec 28 12:43:36 2018 +0300
description:
Interactive shell: initial support of posted events.

diffstat:

njs/njs_shell.c | 49 ++++++++++++++++++++++++++++++++++++-------------
1 files changed, 36 insertions(+), 13 deletions(-)

diffs (103 lines):

diff -r bdd4c516a078 -r f08c5fc1dea8 njs/njs_shell.c
--- a/njs/njs_shell.c Fri Dec 28 12:43:22 2018 +0300
+++ b/njs/njs_shell.c Fri Dec 28 12:43:36 2018 +0300
@@ -54,7 +54,7 @@ static nxt_int_t njs_interactive_shell(n
njs_vm_opt_t *vm_options);
static nxt_int_t njs_process_file(njs_opts_t *opts, njs_vm_opt_t *vm_options);
static nxt_int_t njs_process_script(njs_vm_t *vm, njs_opts_t *opts,
- const nxt_str_t *script, nxt_str_t *out);
+ const nxt_str_t *script);
static nxt_int_t njs_editline_init(njs_vm_t *vm);
static char **njs_completion_handler(const char *text, int start, int end);
static char *njs_completion_generator(const char *text, int state);
@@ -297,7 +297,7 @@ static nxt_int_t
njs_interactive_shell(njs_opts_t *opts, njs_vm_opt_t *vm_options)
{
njs_vm_t *vm;
- nxt_str_t line, out;
+ nxt_str_t line;

vm = njs_vm_create(vm_options);
if (vm == NULL) {
@@ -335,9 +335,7 @@ njs_interactive_shell(njs_opts_t *opts,

add_history((char *) line.start);

- njs_process_script(vm, opts, &line, &out);
-
- printf("%.*s\n", (int) out.length, out.start);
+ njs_process_script(vm, opts, &line);

/* editline allocs a new buffer every time. */
free(line.start);
@@ -357,7 +355,7 @@ njs_process_file(njs_opts_t *opts, njs_v
ssize_t n;
njs_vm_t *vm;
nxt_int_t ret;
- nxt_str_t out, script;
+ nxt_str_t script;
struct stat sb;

file = opts->file;
@@ -448,9 +446,8 @@ njs_process_file(njs_opts_t *opts, njs_v
goto done;
}

- ret = njs_process_script(vm, opts, &script, &out);
+ ret = njs_process_script(vm, opts, &script);
if (ret != NXT_OK) {
- fprintf(stderr, "%.*s\n", (int) out.length, out.start);
ret = NXT_ERROR;
goto done;
}
@@ -473,9 +470,27 @@ close_fd:
}


+static void
+njs_output(njs_vm_t *vm, njs_opts_t *opts, njs_ret_t ret)
+{
+ nxt_str_t out;
+
+ if (njs_vm_retval_dump(vm, &out, 1) != NXT_OK) {
+ out = nxt_string_value("failed to get retval from VM");
+ ret = NJS_ERROR;
+ }
+
+ if (ret != NJS_OK) {
+ fprintf(stderr, "%.*s\n", (int) out.length, out.start);
+
+ } else if (opts->interactive) {
+ printf("%.*s\n", (int) out.length, out.start);
+ }
+}
+
+
static nxt_int_t
-njs_process_script(njs_vm_t *vm, njs_opts_t *opts, const nxt_str_t *script,
- nxt_str_t *out)
+njs_process_script(njs_vm_t *vm, njs_opts_t *opts, const nxt_str_t *script)
{
u_char *start;
nxt_int_t ret;
@@ -493,9 +508,17 @@ njs_process_script(njs_vm_t *vm, njs_opt
ret = njs_vm_start(vm);
}

- if (njs_vm_retval_dump(vm, out, 1) != NXT_OK) {
- *out = nxt_string_value("failed to get retval from VM");
- return NXT_ERROR;
+ njs_output(vm, opts, ret);
+
+ if (ret == NJS_OK) {
+ while (njs_vm_posted(vm)) {
+ ret = njs_vm_run(vm);
+
+ if (ret == NJS_ERROR) {
+ njs_output(vm, opts, ret);
+ return ret;
+ }
+ }
}

return ret;
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Interactive shell: initial support of posted events.

Dmitry Volyntsev 78 December 28, 2018 04:48AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 61
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready