Single threaded ifdef
FossilOrigin-Name: 06ba85d5a4f7912cfce89256d3ff9b3089000c4b1deaddf1c4d42f17c2f25ce1
This commit is contained in:
parent
d2b9d500b2
commit
dce5df9821
7 changed files with 47 additions and 17 deletions
|
@ -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);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "key.h"
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
#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);
|
||||
|
|
11
src/main.c
11
src/main.c
|
@ -46,6 +46,7 @@
|
|||
#include "conversations.h"
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
#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();
|
||||
|
|
|
@ -24,12 +24,7 @@
|
|||
#include "env.h"
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
|
||||
#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
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
|
||||
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;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <fcgi_stdio.h>
|
||||
#include <stddef.h>
|
||||
#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);
|
||||
|
||||
|
|
28
src/request.h
Normal file
28
src/request.h
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef REQUEST_H
|
||||
#define REQUEST_H
|
||||
|
||||
#ifdef SINGLE_THREADED
|
||||
#define REQUEST_T void*
|
||||
#else
|
||||
#define REQUEST_T FCGX_Request*
|
||||
#endif
|
||||
|
||||
#endif /* REQUEST_H */
|
Loading…
Reference in a new issue