summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_application.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2017-03-09 18:03:27 +0300
committerIgor Sysoev <igor@sysoev.ru>2017-03-09 18:03:27 +0300
commit6f2c9acd1841ca20a1388b34aef64e9f00459090 (patch)
treec0b9c1063ec464027d1ca29a793f6c0b7a6878d5 /src/nxt_application.c
parent5745e4826427155e29c1d520fe77811a0f570689 (diff)
downloadunit-6f2c9acd1841ca20a1388b34aef64e9f00459090.tar.gz
unit-6f2c9acd1841ca20a1388b34aef64e9f00459090.tar.bz2
Processes refactoring.
The cycle has been renamed to the runtime.
Diffstat (limited to 'src/nxt_application.c')
-rw-r--r--src/nxt_application.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/src/nxt_application.c b/src/nxt_application.c
index e0e5ffc7..ed661ce7 100644
--- a/src/nxt_application.c
+++ b/src/nxt_application.c
@@ -6,13 +6,14 @@
*/
#include <nxt_main.h>
-#include <nxt_cycle.h>
+#include <nxt_runtime.h>
#include <nxt_application.h>
#define NXT_PARSE_AGAIN (u_char *) -1
+static nxt_int_t nxt_app_listen_socket(nxt_task_t *task, nxt_runtime_t *rt);
static void nxt_app_thread(void *ctx);
static nxt_app_request_t *nxt_app_request_create(nxt_socket_t s,
nxt_log_t *log);
@@ -77,11 +78,15 @@ static nxt_uint_t nxt_app_buf_max_number = 16;
nxt_int_t
-nxt_app_start(nxt_cycle_t *cycle)
+nxt_app_start(nxt_task_t *task, nxt_runtime_t *rt)
{
nxt_thread_link_t *link;
nxt_thread_handle_t handle;
+ if (nxt_app_listen_socket(task, rt) != NXT_OK) {
+ return NXT_ERROR;
+ }
+
if (nxt_slow_path(nxt_thread_mutex_create(&nxt_app_mutex) != NXT_OK)) {
return NXT_ERROR;
}
@@ -94,7 +99,7 @@ nxt_app_start(nxt_cycle_t *cycle)
if (nxt_fast_path(link != NULL)) {
link->start = nxt_app_thread;
- link->data = cycle;
+ link->data = rt;
return nxt_thread_create(&handle, link);
}
@@ -103,6 +108,39 @@ nxt_app_start(nxt_cycle_t *cycle)
}
+static nxt_int_t
+nxt_app_listen_socket(nxt_task_t *task, nxt_runtime_t *rt)
+{
+ nxt_sockaddr_t *sa;
+ nxt_listen_socket_t *ls;
+
+ sa = nxt_sockaddr_alloc(rt->mem_pool, sizeof(struct sockaddr_in),
+ NXT_INET_ADDR_STR_LEN);
+ if (sa == NULL) {
+ return NXT_ERROR;
+ }
+
+ sa->type = SOCK_STREAM;
+ sa->u.sockaddr_in.sin_family = AF_INET;
+ sa->u.sockaddr_in.sin_port = htons(8080);
+
+ nxt_sockaddr_text(sa);
+
+ ls = nxt_runtime_listen_socket_add(rt, sa);
+ if (ls == NULL) {
+ return NXT_ERROR;
+ }
+
+ ls->read_after_accept = 1;
+
+ if (nxt_listen_socket_create(task, ls, 0) != NXT_OK) {
+ return NXT_ERROR;
+ }
+
+ return NXT_OK;
+}
+
+
#define SIZE 4096
static void
@@ -110,9 +148,9 @@ nxt_app_thread(void *ctx)
{
ssize_t n;
nxt_err_t err;
- nxt_cycle_t *cycle;
nxt_socket_t s;
nxt_thread_t *thr;
+ nxt_runtime_t *rt;
nxt_app_request_t *r;
nxt_event_engine_t **engines;
nxt_listen_socket_t *ls;
@@ -124,8 +162,8 @@ nxt_app_thread(void *ctx)
nxt_log_debug(thr->log, "app thread");
- cycle = ctx;
- engines = cycle->engines->elts;
+ rt = ctx;
+ engines = rt->engines->elts;
nxt_app_engine = engines[0];
@@ -138,7 +176,7 @@ nxt_app_thread(void *ctx)
nxt_log_debug(thr->log, "application init failed");
}
- ls = cycle->listen_sockets->elts;
+ ls = rt->listen_sockets->elts;
for ( ;; ) {
nxt_log_debug(thr->log, "wait on accept");