-
-
Save oneman/7df8ad3c14a9f06caaae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/ops/server.c b/lib/ops/server.c | |
index f9a3e2a..a67d6fb 100644 | |
--- a/lib/ops/server.c | |
+++ b/lib/ops/server.c | |
@@ -208,19 +208,21 @@ static int add_route(kr_front_router *router, const char *str) { | |
} | |
static ssize_t say_something(kr_web_path *path, const char *something) { | |
+ kr_web_client *client; | |
kr_http_header hdr; | |
kr_http_response res; | |
uint8_t hdrbuf[512]; | |
size_t sz; | |
size_t hdrsz; | |
printk("trying to send '%s'", something); | |
+ client = kr_web_path_get_client(path); | |
hdrsz = sizeof(hdrbuf); | |
sz = strlen(something); | |
kr_http_response_init(&res, 200); | |
kr_http_length_header_init(&hdr, sz, hdrbuf, hdrsz); | |
kr_http_response_add_header(&res, &hdr); | |
- kr_web_path_pack_http_response(path, &res); | |
- return kr_web_path_pack(path, (uint8_t *)something, sz); | |
+ kr_web_path_pack(path, (uint8_t *) something, sz); | |
+ return kr_web_client_pack_response(client, &res); | |
} | |
static int say_no_no(kr_web_path *path) { | |
@@ -248,13 +250,15 @@ static void do_get(kr_web_path *path) { | |
char json[8192]; | |
kr_ops *server; | |
i = 0; | |
- server = path->web->user; | |
- if ((task = kr_pool_iterate_active(server->task_pool, &i))) { | |
- ret = kr_mt_info_pack_json(json, &task->info, sizeof(json)); | |
- if (ret > 0) { | |
- say_something(path, json); | |
- } else { | |
- say_something(path, "found a task, but couldn't pack it as json."); | |
+ server = kr_web_path_user_get(path); | |
+ if (kr_pool_active(server->task_pool) > 0) { | |
+ while ((task = kr_pool_iterate_active(server->task_pool, &i))) { | |
+ ret = kr_mt_info_pack_json(json, &task->info, sizeof(json)); | |
+ if (ret > 0) { | |
+ say_something(path, json); | |
+ } else { | |
+ say_something(path, "found a task, but couldn't pack it as json."); | |
+ } | |
} | |
} else { | |
say_something(path, "no running tasks."); | |
@@ -262,12 +266,25 @@ static void do_get(kr_web_path *path) { | |
} | |
static void got_headers(kr_ops *server, kr_web_path *path, kr_front_router *router) { | |
- kr_ops_client *client; | |
- client = ops_client_create(server); | |
- client->path = path; | |
- path->user = client; | |
+ kr_ops_client *ops_client; | |
+ kr_web_client *web_client; | |
+ kr_http_request *req; | |
+ ops_client = ops_client_create(server); | |
+ if (ops_client == NULL) { | |
+ return; | |
+ } | |
+ ops_client->path = path; | |
+ kr_web_path_user_set(path, ops_client); | |
printk("Ops: ops client created"); | |
- switch(path->client.http.request.req_line.method) { | |
+ web_client = kr_web_path_get_client(path); | |
+ if (web_client == NULL) { | |
+ return; | |
+ } | |
+ req = kr_web_client_get_request(web_client); | |
+ if (req == NULL) { | |
+ return; | |
+ } | |
+ switch(req->req_line.method) { | |
case KR_HTTP_GET: | |
do_get(path); | |
break; | |
@@ -283,7 +300,7 @@ static void got_headers(kr_ops *server, kr_web_path *path, kr_front_router *rout | |
static void got_close(kr_ops *server, kr_web_path *path) { | |
int ret; | |
kr_ops_client *client; | |
- client = path->user; | |
+ client = kr_web_path_user_get(path); | |
if (client != NULL) { | |
ret = ops_client_destroy(server, client); | |
if (ret == -1) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment