void Handler_task(void *v) { int rc = 0; int i = 0; Handler *handler = (Handler *)v; HandlerParser *parser = NULL; int max_targets = Setting_get_int("limits.handler_targets", 128); log_info("MAX allowing limits.handler_targets=%d", max_targets); parser = HandlerParser_create(max_targets); check_mem(parser); check(Handler_setup(handler) == 0, "Failed to initialize handler, exiting."); while(handler->running && !task_was_signaled()) { taskstate("delivering"); rc = handler_recv_parse(handler, parser); if(task_was_signaled()) { log_warn("Handler task signaled, exiting."); break; } else if( rc == -1 || parser->target_count <= 0) { log_warn("Skipped invalid message from handler: %s", bdata(handler->send_spec)); taskdelay(100); continue; } else { for(i = 0; i < (int)parser->target_count; i++) { int id = (int)parser->targets[i]; int fd = Register_fd_for_id(id); Connection *conn = fd == -1 ? NULL : Register_fd_exists(fd); // don't bother calling process request if there's nothing to handle if(conn && fd >= 0) { handler_process_request(handler, id, fd, conn, parser->body); } else { // TODO: I believe we need to notify the connection that it is dead too Handler_notify_leave(handler, id); } } } HandlerParser_reset(parser); } handler->running = 0; handler->task = NULL; HandlerParser_destroy(parser); taskexit(0); error: log_err("HANDLER TASK DIED: %s", bdata(handler->send_spec)); handler->running = 0; handler->task = NULL; HandlerParser_destroy(parser); taskexit(1); }
int test_parse(const char *test, int target_count) { HandlerParser *parser = HandlerParser_create(128); bstring T1 = bfromcstr(test); int rc = HandlerParser_execute(parser, bdata(T1), blength(T1)); bdestroy(T1); return rc == 1 && target_count == (int)parser->target_count; }
int test_parse(const char *test, int target_count) { HandlerParser *parser = HandlerParser_create(128); bstring T1 = bfromcstr(test); int rc = HandlerParser_execute(parser, bdata(T1), blength(T1)); debug("BODY %d long at %s with rc: %d, uuid: %s, target_count: %d", (int)parser->body_length, parser->body_start, rc, bdata(parser->uuid), (int)parser->target_count); bdestroy(T1); return rc == 1 && target_count == parser->target_count; }
void Handler_task(void *v) { int rc = 0; int i = 0; Handler *handler = (Handler *)v; HandlerParser *parser = NULL; int max_targets = Setting_get_int("limits.handler_targets", 128); log_info("MAX allowing limits.handler_targets=%d", 128); parser = HandlerParser_create(max_targets); check_mem(parser); check(Handler_setup(handler) == 0, "Failed to initialize handler, exiting."); while(handler->running) { taskstate("delivering"); rc = handler_recv_parse(handler, parser); if(rc != -1 && parser->target_count > 0) { for(i = 0; i < (int)parser->target_count; i++) { int id = (int)parser->targets[i]; int fd = Register_fd_for_id(id); Connection *conn = (Connection *)Register_fd_exists(fd); handler_process_request(handler, id, fd, conn, parser->body); } } else { debug("Skipped invalid message from handler: %s", bdata(handler->send_spec)); } HandlerParser_reset(parser); } HandlerParser_destroy(parser); debug("HANDLER EXITED."); taskexit(0); error: HandlerParser_destroy(parser); log_err("HANDLER TASK DIED"); taskexit(1); }