Commit 6b19528a authored by Marek Vavruša's avatar Marek Vavruša

engine: asynchronous start to prevent leaking of messages

parent 62fb9ebb
......@@ -251,7 +251,7 @@ int engine_start(struct engine *engine)
return ret;
}
return uv_run(uv_default_loop(), UV_RUN_DEFAULT);
return kr_ok();
}
void engine_stop(struct engine *engine)
......
......@@ -150,31 +150,39 @@ int main(int argc, char **argv)
loop->data = &worker;
/* Bind to sockets. */
ret = network_listen(&engine.net, addr, (uint16_t)port, NET_UDP|NET_TCP);
if (ret != 0) {
fprintf(stderr, "[system] bind to '%s#%d' %s\n", addr, port, knot_strerror(ret));
ret = EXIT_FAILURE;
} else {
/* Allocate TTY */
uv_pipe_t pipe;
uv_pipe_init(loop, &pipe, 0);
uv_pipe_open(&pipe, 0);
pipe.data = &engine;
if (addr != NULL) {
ret = network_listen(&engine.net, addr, (uint16_t)port, NET_UDP|NET_TCP);
if (ret != 0) {
fprintf(stderr, "[system] bind to '%s#%d' %s\n", addr, port, knot_strerror(ret));
ret = EXIT_FAILURE;
}
}
if (ret == 0) {
/* Interactive stdin */
uv_pipe_t pipe;
if (!feof(stdin)) {
printf("[system] listening on '%s#%d'\n", addr, port);
printf("[system] started in interactive mode, type 'help()'\n");
uv_pipe_init(loop, &pipe, 0);
uv_pipe_open(&pipe, 0);
pipe.data = &engine;
tty_read(NULL, 0, NULL);
uv_read_start((uv_stream_t*) &pipe, tty_alloc, tty_read);
}
/* Run the event loop. */
ret = engine_start(&engine);
if (ret == 0) {
ret = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
}
}
/* Cleanup. */
fprintf(stderr, "\n[system] quitting\n");
engine_deinit(&engine);
if (ret != 0) {
ret = EXIT_FAILURE;
}
return ret;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment