Add workers

This commit is contained in:
2022-12-29 21:41:40 +01:00
parent cff5d558d6
commit 7a2acb0e66
14 changed files with 114 additions and 182 deletions

View File

@ -8,30 +8,9 @@
#include "fastcgi_handler.h"
#include "../logger.h"
#include "../lib/mpmc.h"
#include "../lib/utils.h"
static mpmc_t mpmc_ctx;
static void fastcgi_handler_func(client_ctx_t *ctx);
int fastcgi_handler_init(int n_workers, int buf_size) {
return mpmc_init(&mpmc_ctx, n_workers, buf_size, (void (*)(void *)) fastcgi_handler_func, "fcgi");
}
int fastcgi_handle(client_ctx_t *ctx) {
return mpmc_queue(&mpmc_ctx, ctx);
}
void fastcgi_handler_stop(void) {
mpmc_stop(&mpmc_ctx);
}
void fastcgi_handler_destroy(void) {
mpmc_destroy(&mpmc_ctx);
}
static void fastcgi_handler_func(client_ctx_t *ctx) {
void fastcgi_handler_func(client_ctx_t *ctx) {
logger_set_prefix("[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
// TODO
}

View File

@ -11,12 +11,6 @@
#include "../server.h"
int fastcgi_handler_init(int n_workers, int buf_size);
int fastcgi_handle(client_ctx_t *ctx);
void fastcgi_handler_stop(void);
void fastcgi_handler_destroy(void);
void fastcgi_handler_func(client_ctx_t *ctx);
#endif //SESIMOS_FASTCGI_HANDLER_H

View File

@ -8,52 +8,23 @@
#include "../defs.h"
#include "request_handler.h"
#include "../workers.h"
#include "../lib/mpmc.h"
#include "tcp_closer.h"
#include "../async.h"
#include "../server.h"
#include "../logger.h"
#include "../lib/utils.h"
#include "../lib/config.h"
#include "../lib/sock.h"
#include "../lib/http.h"
#include "../lib/proxy.h"
#include "../lib/fastcgi.h"
#include "../cache_handler.h"
#include "../lib/compress.h"
#include "../lib/websocket.h"
#include "responder.h"
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <openssl/err.h>
#include <arpa/inet.h>
static mpmc_t mpmc_ctx;
static void request_handler_func(client_ctx_t *ctx);
static int request_handler(client_ctx_t *ctx);
int request_handler_init(int n_workers, int buf_size) {
return mpmc_init(&mpmc_ctx, n_workers, buf_size, (void (*)(void *)) request_handler_func, "req");
}
int handle_request(client_ctx_t *ctx) {
return mpmc_queue(&mpmc_ctx, ctx);
}
void request_handler_stop(void) {
mpmc_stop(&mpmc_ctx);
}
void request_handler_destroy(void) {
mpmc_destroy(&mpmc_ctx);
}
static void request_handler_func(client_ctx_t *ctx) {
void request_handler_func(client_ctx_t *ctx) {
logger_set_prefix("[%*s]%s", INET6_ADDRSTRLEN, ctx->s_addr, ctx->log_prefix);
if (request_handler(ctx) == 0) {

View File

@ -11,12 +11,6 @@
#include "../server.h"
int request_handler_init(int n_workers, int buf_size);
int handle_request(client_ctx_t *ctx);
void request_handler_stop(void);
void request_handler_destroy(void);
void request_handler_func(client_ctx_t *ctx);
#endif //SESIMOS_REQUEST_HANDLER_H

View File

@ -8,48 +8,23 @@
#include "../defs.h"
#include "responder.h"
#include "../lib/mpmc.h"
#include "tcp_closer.h"
#include "../async.h"
#include "../logger.h"
#include "../lib/utils.h"
#include "../lib/config.h"
#include "../lib/sock.h"
#include "../lib/http.h"
#include "../lib/proxy.h"
#include "../lib/fastcgi.h"
#include "../lib/compress.h"
#include "../lib/websocket.h"
#include "request_handler.h"
#include "../workers.h"
#include <string.h>
#include <unistd.h>
#include <openssl/err.h>
#include <arpa/inet.h>
static mpmc_t mpmc_ctx;
static void responder_func(client_ctx_t *ctx);
static void responder(client_ctx_t *ctx);
int responder_init(int n_workers, int buf_size) {
return mpmc_init(&mpmc_ctx, n_workers, buf_size, (void (*)(void *)) responder_func, "res");
}
int respond(client_ctx_t *ctx) {
return mpmc_queue(&mpmc_ctx, ctx);
}
void responder_stop(void) {
mpmc_stop(&mpmc_ctx);
}
void responder_destroy(void) {
mpmc_destroy(&mpmc_ctx);
}
static void responder_func(client_ctx_t *ctx) {
void responder_func(client_ctx_t *ctx) {
logger_set_prefix("[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
responder(ctx);

View File

@ -11,12 +11,6 @@
#include "../server.h"
int responder_init(int n_workers, int buf_size);
int respond(client_ctx_t *ctx);
void responder_stop(void);
void responder_destroy(void);
void responder_func(client_ctx_t *ctx);
#endif //SESIMOS_RESPONDER_H

View File

@ -6,43 +6,20 @@
* @date 2022-12-28
*/
#include "../server.h"
#include "tcp_acceptor.h"
#include "../async.h"
#include "../logger.h"
#include "../lib/mpmc.h"
#include "../lib/utils.h"
#include "../lib/geoip.h"
#include "../lib/config.h"
#include "tcp_closer.h"
#include "request_handler.h"
#include "tcp_acceptor.h"
#include "../workers.h"
#include <string.h>
#include <errno.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
static mpmc_t mpmc_ctx;
static void tcp_acceptor_func(client_ctx_t *ctx);
int tcp_acceptor_init(int n_workers, int buf_size) {
return mpmc_init(&mpmc_ctx, n_workers, buf_size, (void (*)(void *)) tcp_acceptor_func, "tcp_a");
}
int tcp_accept(client_ctx_t *ctx) {
return mpmc_queue(&mpmc_ctx, ctx);
}
void tcp_acceptor_stop(void) {
mpmc_stop(&mpmc_ctx);
}
void tcp_acceptor_destroy(void) {
mpmc_destroy(&mpmc_ctx);
}
static void tcp_acceptor_func(client_ctx_t *ctx) {
void tcp_acceptor_func(client_ctx_t *ctx) {
struct sockaddr_in6 server_addr;
inet_ntop(ctx->socket.addr.ipv6.sin6_family, &ctx->socket.addr.ipv6.sin6_addr, ctx->_c_addr, sizeof(ctx->_c_addr));

View File

@ -11,12 +11,6 @@
#include "../server.h"
int tcp_acceptor_init(int n_workers, int buf_size);
int tcp_accept(client_ctx_t *ctx);
void tcp_acceptor_stop(void);
void tcp_acceptor_destroy(void);
void tcp_acceptor_func(client_ctx_t *ctx);
#endif //SESIMOS_TCP_ACCEPTOR_H

View File

@ -8,32 +8,11 @@
#include "tcp_closer.h"
#include "../logger.h"
#include "../lib/mpmc.h"
#include "../lib/utils.h"
#include <memory.h>
static mpmc_t mpmc_ctx;
static void tcp_closer_func(client_ctx_t *ctx);
int tcp_closer_init(int n_workers, int buf_size) {
return mpmc_init(&mpmc_ctx, n_workers, buf_size, (void (*)(void *)) tcp_closer_func, "tcp_c");
}
int tcp_close(client_ctx_t *ctx) {
return mpmc_queue(&mpmc_ctx, ctx);
}
void tcp_closer_stop(void) {
mpmc_stop(&mpmc_ctx);
}
void tcp_closer_destroy(void) {
mpmc_destroy(&mpmc_ctx);
}
static void tcp_closer_func(client_ctx_t *ctx) {
void tcp_closer_func(client_ctx_t *ctx) {
logger_set_prefix("[%*s]%s", INET6_ADDRSTRLEN, ctx->s_addr, ctx->log_prefix);
sock_close(&ctx->socket);

View File

@ -11,12 +11,6 @@
#include "../server.h"
int tcp_closer_init(int n_workers, int buf_size);
int tcp_close(client_ctx_t *ctx);
void tcp_closer_stop(void);
void tcp_closer_destroy(void);
void tcp_closer_func(client_ctx_t *ctx);
#endif //SESIMOS_TCP_CLOSER_H