Request handler
This commit is contained in:
@ -52,7 +52,8 @@ void client_terminate(int _) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int client_request_handler(client_ctx_t *cctx, sock *client, unsigned long client_num, unsigned int req_num, const char *restrict log_client_prefix) {
|
int client_request_handler(client_ctx_t *cctx) {
|
||||||
|
sock *client = &cctx->socket;
|
||||||
struct timespec begin, end;
|
struct timespec begin, end;
|
||||||
long ret;
|
long ret;
|
||||||
|
|
||||||
@ -140,7 +141,7 @@ int client_request_handler(client_ctx_t *cctx, sock *client, unsigned long clien
|
|||||||
strcpy(host, host_ptr);
|
strcpy(host, host_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(log_req_prefix, "[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, host, CLR_STR, log_client_prefix);
|
sprintf(log_req_prefix, "[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, host, CLR_STR, cctx->log_prefix);
|
||||||
logger_set_prefix(log_req_prefix);
|
logger_set_prefix(log_req_prefix);
|
||||||
info(BLD_STR "%s %s", req.method, req.uri);
|
info(BLD_STR "%s %s", req.method, req.uri);
|
||||||
|
|
||||||
@ -378,7 +379,7 @@ int client_request_handler(client_ctx_t *cctx, sock *client, unsigned long clien
|
|||||||
http_add_header_field(&res.hdr, "Last-Modified", last_modified);
|
http_add_header_field(&res.hdr, "Last-Modified", last_modified);
|
||||||
|
|
||||||
res.status = http_get_status(200);
|
res.status = http_get_status(200);
|
||||||
if (fastcgi_init(&fcgi_conn, mode, client_num, req_num, client, &req, &uri) != 0) {
|
if (fastcgi_init(&fcgi_conn, mode, 0 /* TODO */, cctx->req_num, client, &req, &uri) != 0) {
|
||||||
res.status = http_get_status(503);
|
res.status = http_get_status(503);
|
||||||
sprintf(err_msg, "Unable to communicate with FastCGI socket.");
|
sprintf(err_msg, "Unable to communicate with FastCGI socket.");
|
||||||
goto respond;
|
goto respond;
|
||||||
@ -783,7 +784,7 @@ int client_connection_handler(client_ctx_t *ctx, unsigned long client_num, const
|
|||||||
ctx->s_keep_alive = 1;
|
ctx->s_keep_alive = 1;
|
||||||
ctx->c_keep_alive = 1;
|
ctx->c_keep_alive = 1;
|
||||||
while (ctx->c_keep_alive && ctx->s_keep_alive && req_num < REQ_PER_CONNECTION) {
|
while (ctx->c_keep_alive && ctx->s_keep_alive && req_num < REQ_PER_CONNECTION) {
|
||||||
ret = client_request_handler(ctx, client, client_num, req_num++, log_client_prefix);
|
ret = client_request_handler(ctx);
|
||||||
logger_set_prefix(log_conn_prefix);
|
logger_set_prefix(log_conn_prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,6 @@ typedef struct {
|
|||||||
|
|
||||||
host_config_t *get_host_config(const char *host);
|
host_config_t *get_host_config(const char *host);
|
||||||
|
|
||||||
void *client_handler(client_ctx_t *client);
|
int client_request_handler(client_ctx_t *cctx);
|
||||||
|
|
||||||
#endif //SESIMOS_CLIENT_H
|
#endif //SESIMOS_CLIENT_H
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "../lib/mpmc.h"
|
#include "../lib/mpmc.h"
|
||||||
#include "../lib/utils.h"
|
#include "../lib/utils.h"
|
||||||
#include "tcp_closer.h"
|
#include "tcp_closer.h"
|
||||||
|
#include "../async.h"
|
||||||
|
#include "../server.h"
|
||||||
|
|
||||||
static mpmc_t mpmc_ctx;
|
static mpmc_t mpmc_ctx;
|
||||||
|
|
||||||
@ -26,6 +28,12 @@ void request_handler_destroy(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void request_handler_func(client_ctx_t *ctx) {
|
static void request_handler_func(client_ctx_t *ctx) {
|
||||||
// TODO
|
client_request_handler(ctx);
|
||||||
|
|
||||||
|
if (ctx->c_keep_alive && ctx->s_keep_alive && ctx->req_num < REQ_PER_CONNECTION) {
|
||||||
|
async(ctx->socket.socket, POLLIN, 0, (void (*)(void *)) handle_request, ctx, (void (*)(void *)) tcp_close, ctx);
|
||||||
|
logger_set_prefix(ctx->log_prefix);
|
||||||
|
} else {
|
||||||
tcp_close(ctx);
|
tcp_close(ctx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user