From dce5df9821014ae6091f12fb5733dc42dd9a6253 Mon Sep 17 00:00:00 2001 From: nekobit Date: Tue, 23 Aug 2022 18:50:34 +0000 Subject: [PATCH] Single threaded ifdef FossilOrigin-Name: 06ba85d5a4f7912cfce89256d3ff9b3089000c4b1deaddf1c4d42f17c2f25ce1 --- src/cookie.c | 2 +- src/cookie.h | 3 ++- src/main.c | 11 ++++++++--- src/path.h | 7 +------ src/query.c | 6 +++--- src/query.h | 7 ++++--- src/request.h | 28 ++++++++++++++++++++++++++++ 7 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 src/request.h diff --git a/src/cookie.c b/src/cookie.c index b0cf02e..045faa7 100644 --- a/src/cookie.c +++ b/src/cookie.c @@ -29,7 +29,7 @@ enum cookie_state STATE_V_START, }; -char* read_cookies_env(FCGX_Request* req, struct cookie_values* cookies) +char* read_cookies_env(REQUEST_T req, struct cookie_values* cookies) { struct http_cookie_info info; char* cookies_env = GET_ENV("HTTP_COOKIE", req); diff --git a/src/cookie.h b/src/cookie.h index 0381de7..b462427 100644 --- a/src/cookie.h +++ b/src/cookie.h @@ -23,6 +23,7 @@ #include "key.h" #include #include +#include "request.h" struct cookie_values { @@ -61,7 +62,7 @@ struct http_cookie_info // Stupidly fast simple cookie parser char* parse_cookies(char* begin, struct http_cookie_info* info); -char* read_cookies_env(FCGX_Request* req, struct cookie_values* cookies); +char* read_cookies_env(REQUEST_T req, struct cookie_values* cookies); int cookie_get_val(char* src, char* key, struct http_cookie_info* info); HV* perlify_cookies(struct cookie_values* cookies); diff --git a/src/main.c b/src/main.c index 6f8cdb7..48416f3 100644 --- a/src/main.c +++ b/src/main.c @@ -46,6 +46,7 @@ #include "conversations.h" #include #include +#include "request.h" #define THREAD_COUNT 20 @@ -115,7 +116,7 @@ static struct path_info paths[] = { { "/treebird_api/v1/attachment", api_attachment_create }, }; -static void application(mastodont_t* api, FCGX_Request* req) +static void application(mastodont_t* api, REQUEST_T req) { // Default config struct session ssn = { @@ -174,7 +175,8 @@ static void application(mastodont_t* api, FCGX_Request* req) cleanup_media_storages(&ssn, attachments); } -static void* cgi_start(void* arg) +#ifndef SINGLE_THREADED +static void* threaded_fcgi_start(void* arg) { mastodont_t* api = arg; int rc; @@ -198,6 +200,7 @@ static void* cgi_start(void* arg) return NULL; } +#endif EXTERN_C void xs_init(pTHX) { @@ -230,6 +233,7 @@ int main(int argc, char **argv, char **env) // Fetch information about the current instance load_instance_info_cache(&api); +#ifndef SINGLE_THREADED // Start thread pool pthread_t id[THREAD_COUNT]; @@ -237,12 +241,13 @@ int main(int argc, char **argv, char **env) pthread_create(&id[i], NULL, cgi_start, &api); // Hell, let's not sit around here either - cgi_start(&api); +threaded_fcgi_start(&api); FCGX_ShutdownPending(); for (unsigned i = 0; i < THREAD_COUNT; ++i) pthread_join(id[i], NULL); +#endif free_instance_info_cache(); mastodont_global_curl_cleanup(); diff --git a/src/path.h b/src/path.h index 243f1fd..2b0aceb 100644 --- a/src/path.h +++ b/src/path.h @@ -24,12 +24,7 @@ #include "env.h" #include #include - -#ifdef SINGLE_THREADED -#define REQUEST_T void* -#else -#define REQUEST_T FCGX_Request* -#endif +#include "request.h" #define PATH_ARGS REQUEST_T req, struct session* ssn, mastodont_t* api, char** data diff --git a/src/query.c b/src/query.c index 4943799..5755a17 100644 --- a/src/query.c +++ b/src/query.c @@ -26,7 +26,7 @@ #include #include -char* read_get_data(FCGX_Request* req, struct get_values* query) +char* read_get_data(REQUEST_T req, struct get_values* query) { struct http_query_info info = { 0 }; char* query_string = GET_ENV("QUERY_STRING", req); @@ -76,7 +76,7 @@ char* read_get_data(FCGX_Request* req, struct get_values* query) -char* read_post_data(FCGX_Request* req, struct post_values* post) +char* read_post_data(REQUEST_T req, struct post_values* post) { ptrdiff_t begin_curr_size; struct http_query_info query_info; @@ -212,7 +212,7 @@ char* parse_query(char* begin, struct http_query_info* info) return end ? NULL : begin+1; } -char* try_handle_post(FCGX_Request* req, void (*call)(struct http_query_info*, void*), void* arg) +char* try_handle_post(REQUEST_T req, void (*call)(struct http_query_info*, void*), void* arg) { char* request_method = GET_ENV("REQUEST_METHOD", req); char* post_query = NULL, * p_query_read; diff --git a/src/query.h b/src/query.h index a7953bd..282d2f7 100644 --- a/src/query.h +++ b/src/query.h @@ -22,6 +22,7 @@ #include #include #include "key.h" +#include "request.h" struct http_query_info { @@ -83,11 +84,11 @@ struct get_values struct key type; // Int }; -char* read_get_data(FCGX_Request* req, struct get_values* query); -char* read_post_data(FCGX_Request* req, struct post_values* post); +char* read_get_data(REQUEST_T req, struct get_values* query); +char* read_post_data(REQUEST_T req, struct post_values* post); /* A stupidly quick query parser */ char* parse_query(char* begin, struct http_query_info* info); -char* try_handle_post(FCGX_Request* req, void (*call)(struct http_query_info*, void*), void* arg); +char* try_handle_post(REQUEST_T req, void (*call)(struct http_query_info*, void*), void* arg); void free_files(struct file_array* files); diff --git a/src/request.h b/src/request.h new file mode 100644 index 0000000..22b5ee5 --- /dev/null +++ b/src/request.h @@ -0,0 +1,28 @@ +/* + * Treebird - Lightweight frontend for Pleroma + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef REQUEST_H +#define REQUEST_H + +#ifdef SINGLE_THREADED +#define REQUEST_T void* +#else +#define REQUEST_T FCGX_Request* +#endif + +#endif /* REQUEST_H */