Made it easier to run multiple instances.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3687 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
33
src/task.c
33
src/task.c
@ -91,7 +91,7 @@ typedef struct _tf_task_t {
|
||||
promise_t* _promises;
|
||||
int _promise_count;
|
||||
promiseid_t _nextPromise;
|
||||
uv_loop_t* _loop;
|
||||
uv_loop_t _loop;
|
||||
|
||||
export_record_t* _exports;
|
||||
int _export_count;
|
||||
@ -105,8 +105,8 @@ typedef struct _tf_task_t {
|
||||
int _ssb_port;
|
||||
int _http_port;
|
||||
int _https_port;
|
||||
const char* _db_path;
|
||||
const char* _secrets_path;
|
||||
char _db_path[256];
|
||||
char _secrets_path[256];
|
||||
} tf_task_t;
|
||||
|
||||
typedef struct _export_record_t {
|
||||
@ -294,7 +294,7 @@ static JSValue _task_setTimeout(JSContext* context, JSValueConst this_val, int a
|
||||
|
||||
uv_timer_t* timer = malloc(sizeof(uv_timer_t));
|
||||
memset(timer, 0, sizeof(uv_timer_t));
|
||||
uv_timer_init(task->_loop, timer);
|
||||
uv_timer_init(&task->_loop, timer);
|
||||
timer->data = timeout;
|
||||
|
||||
int64_t duration;
|
||||
@ -882,7 +882,7 @@ static const char* _tf_task_resolveRequire(tf_task_t* task, const char* require)
|
||||
snprintf(test, sizeof(test), "%s/%s%s", task->_path, require, strstr(require, ".js") ? "" : ".js");
|
||||
printf("Testing %s\n", test);
|
||||
uv_fs_t request;
|
||||
if (uv_fs_access(task->_loop, &request, test, R_OK, 0) == 0)
|
||||
if (uv_fs_access(&task->_loop, &request, test, R_OK, 0) == 0)
|
||||
{
|
||||
return strdup(test);
|
||||
}
|
||||
@ -1049,7 +1049,7 @@ JSValue _tf_task_sandbox_require(JSContext* context, JSValueConst this_val, int
|
||||
|
||||
uv_loop_t* tf_task_get_loop(tf_task_t* task)
|
||||
{
|
||||
return task->_loop;
|
||||
return &task->_loop;
|
||||
}
|
||||
|
||||
static promise_t* _tf_task_find_promise(tf_task_t* task, promiseid_t id)
|
||||
@ -1219,8 +1219,6 @@ tf_task_t* tf_task_create()
|
||||
{
|
||||
tf_task_t* task = malloc(sizeof(tf_task_t));
|
||||
*task = (tf_task_t) { 0 };
|
||||
task->_loop = uv_loop_new();
|
||||
task->_loop->data = task;
|
||||
++_count;
|
||||
task->_runtime = JS_NewRuntime();
|
||||
task->_context = JS_NewContext(task->_runtime);
|
||||
@ -1229,7 +1227,8 @@ tf_task_t* tf_task_create()
|
||||
JS_SetHostPromiseRejectionTracker(task->_runtime, _tf_task_promise_rejection_tracker, task);
|
||||
|
||||
JS_NewClassID(&_import_class_id);
|
||||
JSClassDef def = {
|
||||
JSClassDef def =
|
||||
{
|
||||
.class_name = "imported_function",
|
||||
.finalizer = _import_finalizer,
|
||||
.gc_mark = _import_mark_func,
|
||||
@ -1237,6 +1236,8 @@ tf_task_t* tf_task_create()
|
||||
};
|
||||
JS_NewClass(task->_runtime, _import_class_id, &def);
|
||||
task->_loadedFiles = JS_NewObject(task->_context);
|
||||
uv_loop_init(&task->_loop);
|
||||
task->_loop.data = task;
|
||||
return task;
|
||||
}
|
||||
|
||||
@ -1263,7 +1264,7 @@ void tf_task_activate(tf_task_t* task)
|
||||
|
||||
if (task->_trusted)
|
||||
{
|
||||
sqlite3_open(task->_db_path ? task->_db_path : "db.sqlite", &task->_db);
|
||||
sqlite3_open(*task->_db_path ? task->_db_path : "db.sqlite", &task->_db);
|
||||
|
||||
JS_SetPropertyStr(context, global, "require", JS_NewCFunction(context, _tf_task_require, "require", 1));
|
||||
JS_SetPropertyStr(context, global, "Task", tf_taskstub_register(context));
|
||||
@ -1274,7 +1275,7 @@ void tf_task_activate(tf_task_t* task)
|
||||
|
||||
task->_trace = tf_trace_create();
|
||||
|
||||
task->_ssb = tf_ssb_create(task->_loop, task->_context, task->_db, task->_secrets_path);
|
||||
task->_ssb = tf_ssb_create(&task->_loop, task->_context, task->_db, *task->_secrets_path ? task->_secrets_path : NULL);
|
||||
tf_ssb_set_trace(task->_ssb, task->_trace);
|
||||
tf_ssb_register(context, task->_ssb);
|
||||
|
||||
@ -1302,7 +1303,7 @@ void tf_task_activate(tf_task_t* task)
|
||||
|
||||
void tf_task_run(tf_task_t* task)
|
||||
{
|
||||
uv_run(task->_loop, UV_RUN_DEFAULT);
|
||||
uv_run(&task->_loop, UV_RUN_DEFAULT);
|
||||
}
|
||||
|
||||
void tf_task_set_trusted(tf_task_t* task, bool trusted)
|
||||
@ -1377,8 +1378,8 @@ void tf_task_destroy(tf_task_t* task)
|
||||
sqlite3_close(task->_db);
|
||||
}
|
||||
|
||||
uv_print_all_handles(task->_loop, stdout);
|
||||
uv_loop_delete(task->_loop);
|
||||
uv_print_all_handles(&task->_loop, stdout);
|
||||
uv_loop_close(&task->_loop);
|
||||
--_count;
|
||||
free((void*)task->_path);
|
||||
free(task);
|
||||
@ -1454,12 +1455,12 @@ void tf_task_set_https_port(tf_task_t* task, int port)
|
||||
|
||||
void tf_task_set_db_path(tf_task_t* task, const char* db_path)
|
||||
{
|
||||
task->_db_path = db_path;
|
||||
snprintf(task->_db_path, sizeof(task->_db_path), "%s", db_path);
|
||||
}
|
||||
|
||||
void tf_task_set_secrets_path(tf_task_t* task, const char* secrets_path)
|
||||
{
|
||||
task->_secrets_path = secrets_path;
|
||||
snprintf(task->_secrets_path, sizeof(task->_secrets_path), "%s", secrets_path);
|
||||
}
|
||||
|
||||
const char* tf_task_get_name(tf_task_t* task)
|
||||
|
Reference in New Issue
Block a user