Remove tcp_closer
This commit is contained in:
4
Makefile
4
Makefile
@ -46,7 +46,7 @@ bin/worker/%.o: src/worker/%.c
|
|||||||
$(CC) -c -o $@ $(CFLAGS) $<
|
$(CC) -c -o $@ $(CFLAGS) $<
|
||||||
|
|
||||||
bin/sesimos: bin/server.o bin/logger.o bin/cache_handler.o bin/async.o bin/workers.o \
|
bin/sesimos: bin/server.o bin/logger.o bin/cache_handler.o bin/async.o bin/workers.o \
|
||||||
bin/worker/request_handler.o bin/worker/tcp_acceptor.o bin/worker/tcp_closer.o \
|
bin/worker/request_handler.o bin/worker/tcp_acceptor.o \
|
||||||
bin/worker/fastcgi_handler.o bin/worker/local_handler.o bin/worker/proxy_handler.o \
|
bin/worker/fastcgi_handler.o bin/worker/local_handler.o bin/worker/proxy_handler.o \
|
||||||
bin/lib/compress.o bin/lib/config.o bin/lib/fastcgi.o bin/lib/geoip.o \
|
bin/lib/compress.o bin/lib/config.o bin/lib/fastcgi.o bin/lib/geoip.o \
|
||||||
bin/lib/http.o bin/lib/http_static.o bin/lib/proxy.o bin/lib/sock.o bin/lib/uri.o \
|
bin/lib/http.o bin/lib/http_static.o bin/lib/proxy.o bin/lib/sock.o bin/lib/uri.o \
|
||||||
@ -69,8 +69,6 @@ bin/worker/request_handler.o: src/worker/func.h
|
|||||||
|
|
||||||
bin/worker/tcp_acceptor.o: src/worker/func.h
|
bin/worker/tcp_acceptor.o: src/worker/func.h
|
||||||
|
|
||||||
bin/worker/tcp_closer.o: src/worker/func.h
|
|
||||||
|
|
||||||
bin/worker/fastcgi_handler.o: src/worker/func.h
|
bin/worker/fastcgi_handler.o: src/worker/func.h
|
||||||
|
|
||||||
bin/worker/local_handler.o: src/worker/func.h
|
bin/worker/local_handler.o: src/worker/func.h
|
||||||
|
@ -44,8 +44,6 @@ typedef struct {
|
|||||||
|
|
||||||
void tcp_acceptor_func(client_ctx_t *ctx);
|
void tcp_acceptor_func(client_ctx_t *ctx);
|
||||||
|
|
||||||
void tcp_closer_func(client_ctx_t *ctx);
|
|
||||||
|
|
||||||
void request_handler_func(client_ctx_t *ctx);
|
void request_handler_func(client_ctx_t *ctx);
|
||||||
|
|
||||||
void local_handler_func(client_ctx_t *ctx);
|
void local_handler_func(client_ctx_t *ctx);
|
||||||
@ -58,6 +56,8 @@ void ws_frame_handler_func(ws_ctx_t *ctx);
|
|||||||
|
|
||||||
int respond(client_ctx_t *ctx);
|
int respond(client_ctx_t *ctx);
|
||||||
|
|
||||||
int request_complete(client_ctx_t *ctx);
|
void request_complete(client_ctx_t *ctx);
|
||||||
|
|
||||||
|
void tcp_close(client_ctx_t *ctx);
|
||||||
|
|
||||||
#endif //SESIMOS_FUNC_H
|
#endif //SESIMOS_FUNC_H
|
||||||
|
@ -350,7 +350,7 @@ int respond(client_ctx_t *ctx) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int request_complete(client_ctx_t *ctx) {
|
void request_complete(client_ctx_t *ctx) {
|
||||||
// FIXME
|
// FIXME
|
||||||
//if (close_proxy && proxy.socket != 0) {
|
//if (close_proxy && proxy.socket != 0) {
|
||||||
// info(BLUE_STR "Closing proxy connection");
|
// info(BLUE_STR "Closing proxy connection");
|
||||||
@ -364,6 +364,4 @@ int request_complete(client_ctx_t *ctx) {
|
|||||||
uri_free(&ctx->uri);
|
uri_free(&ctx->uri);
|
||||||
http_free_req(&ctx->req);
|
http_free_req(&ctx->req);
|
||||||
http_free_res(&ctx->res);
|
http_free_res(&ctx->res);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -116,3 +116,15 @@ static int tcp_acceptor(client_ctx_t *ctx) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tcp_close(client_ctx_t *ctx) {
|
||||||
|
logger_set_prefix("[%*s]%s", INET6_ADDRSTRLEN, ctx->socket.s_addr, ctx->log_prefix);
|
||||||
|
|
||||||
|
sock_close(&ctx->socket);
|
||||||
|
|
||||||
|
ctx->cnx_e = clock_micros();
|
||||||
|
char buf[32];
|
||||||
|
info("Connection closed (%s)", format_duration(ctx->cnx_e - ctx->cnx_s, buf));
|
||||||
|
|
||||||
|
memset(ctx, 0, sizeof(*ctx));
|
||||||
|
}
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
/**
|
|
||||||
* sesimos - secure, simple, modern web server
|
|
||||||
* @brief TCP closer
|
|
||||||
* @file src/worker/tcp_closer.c
|
|
||||||
* @author Lorenz Stechauner
|
|
||||||
* @date 2022-12-28
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "func.h"
|
|
||||||
#include "../logger.h"
|
|
||||||
#include "../lib/utils.h"
|
|
||||||
|
|
||||||
#include <memory.h>
|
|
||||||
|
|
||||||
void tcp_closer_func(client_ctx_t *ctx) {
|
|
||||||
logger_set_prefix("[%*s]%s", INET6_ADDRSTRLEN, ctx->socket.s_addr, ctx->log_prefix);
|
|
||||||
|
|
||||||
sock_close(&ctx->socket);
|
|
||||||
|
|
||||||
ctx->cnx_e = clock_micros();
|
|
||||||
char buf[32];
|
|
||||||
info("Connection closed (%s)", format_duration(ctx->cnx_e - ctx->cnx_s, buf));
|
|
||||||
|
|
||||||
memset(ctx, 0, sizeof(*ctx));
|
|
||||||
}
|
|
@ -12,12 +12,11 @@
|
|||||||
#include "worker/func.h"
|
#include "worker/func.h"
|
||||||
#include "async.h"
|
#include "async.h"
|
||||||
|
|
||||||
static mpmc_t tcp_acceptor_ctx, tcp_closer_ctx, request_handler_ctx,
|
static mpmc_t tcp_acceptor_ctx, request_handler_ctx,
|
||||||
local_handler_ctx, fastcgi_handler_cxt, proxy_handler_ctx;
|
local_handler_ctx, fastcgi_handler_cxt, proxy_handler_ctx;
|
||||||
|
|
||||||
int workers_init(void) {
|
int workers_init(void) {
|
||||||
mpmc_init(&tcp_acceptor_ctx, 8, 64, (void (*)(void *)) tcp_acceptor_func, "tcp_a");
|
mpmc_init(&tcp_acceptor_ctx, 8, 64, (void (*)(void *)) tcp_acceptor_func, "tcp");
|
||||||
mpmc_init(&tcp_closer_ctx, 8, 64, (void (*)(void *)) tcp_closer_func, "tcp_c");
|
|
||||||
mpmc_init(&request_handler_ctx, 16, 64, (void (*)(void *)) request_handler_func, "req");
|
mpmc_init(&request_handler_ctx, 16, 64, (void (*)(void *)) request_handler_func, "req");
|
||||||
mpmc_init(&local_handler_ctx, 16, 64, (void (*)(void *)) local_handler_func, "local");
|
mpmc_init(&local_handler_ctx, 16, 64, (void (*)(void *)) local_handler_func, "local");
|
||||||
mpmc_init(&fastcgi_handler_cxt, 16, 64, (void (*)(void *)) fastcgi_handler_func, "fcgi");
|
mpmc_init(&fastcgi_handler_cxt, 16, 64, (void (*)(void *)) fastcgi_handler_func, "fcgi");
|
||||||
@ -31,7 +30,6 @@ void workers_stop(void) {
|
|||||||
mpmc_stop(&fastcgi_handler_cxt);
|
mpmc_stop(&fastcgi_handler_cxt);
|
||||||
mpmc_stop(&proxy_handler_ctx);
|
mpmc_stop(&proxy_handler_ctx);
|
||||||
mpmc_stop(&request_handler_ctx);
|
mpmc_stop(&request_handler_ctx);
|
||||||
mpmc_stop(&tcp_closer_ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void workers_destroy(void) {
|
void workers_destroy(void) {
|
||||||
@ -40,17 +38,12 @@ void workers_destroy(void) {
|
|||||||
mpmc_destroy(&fastcgi_handler_cxt);
|
mpmc_destroy(&fastcgi_handler_cxt);
|
||||||
mpmc_destroy(&proxy_handler_ctx);
|
mpmc_destroy(&proxy_handler_ctx);
|
||||||
mpmc_destroy(&request_handler_ctx);
|
mpmc_destroy(&request_handler_ctx);
|
||||||
mpmc_destroy(&tcp_closer_ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int tcp_accept(client_ctx_t *ctx) {
|
int tcp_accept(client_ctx_t *ctx) {
|
||||||
return mpmc_queue(&tcp_acceptor_ctx, ctx);
|
return mpmc_queue(&tcp_acceptor_ctx, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tcp_close(client_ctx_t *ctx) {
|
|
||||||
return mpmc_queue(&tcp_closer_ctx, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int handle_request_cb(client_ctx_t *ctx) {
|
static int handle_request_cb(client_ctx_t *ctx) {
|
||||||
return mpmc_queue(&request_handler_ctx, ctx);
|
return mpmc_queue(&request_handler_ctx, ctx);
|
||||||
}
|
}
|
||||||
@ -59,7 +52,8 @@ int handle_request(client_ctx_t *ctx) {
|
|||||||
if (ctx->c_keep_alive && ctx->s_keep_alive) {
|
if (ctx->c_keep_alive && ctx->s_keep_alive) {
|
||||||
return async(ctx->socket.socket, POLLIN, 0, (void (*)(void *)) handle_request_cb, ctx, (void (*)(void *)) tcp_close, ctx);
|
return async(ctx->socket.socket, POLLIN, 0, (void (*)(void *)) handle_request_cb, ctx, (void (*)(void *)) tcp_close, ctx);
|
||||||
} else {
|
} else {
|
||||||
return tcp_close(ctx);
|
tcp_close(ctx);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@ void workers_destroy(void);
|
|||||||
|
|
||||||
int tcp_accept(client_ctx_t *ctx);
|
int tcp_accept(client_ctx_t *ctx);
|
||||||
|
|
||||||
int tcp_close(client_ctx_t *ctx);
|
|
||||||
|
|
||||||
int handle_request(client_ctx_t *ctx);
|
int handle_request(client_ctx_t *ctx);
|
||||||
|
|
||||||
int local_handle(client_ctx_t *ctx);
|
int local_handle(client_ctx_t *ctx);
|
||||||
|
Reference in New Issue
Block a user