feat(lnm): add some internal logging
parent
3aa0ace863
commit
dde83584a7
|
@ -6,9 +6,12 @@
|
|||
#include "lnm/http/loop.h"
|
||||
#include "lnm/http/loop_internal.h"
|
||||
#include "lnm/http/req.h"
|
||||
#include "lnm/log.h"
|
||||
#include "lnm/loop.h"
|
||||
#include "lnm/loop_internal.h"
|
||||
|
||||
static const char *section = "http";
|
||||
|
||||
/* static const lnm_http_loop_state lnm_http_loop_state_first_req =
|
||||
* lnm_http_loop_state_parse_req; */
|
||||
static const lnm_http_loop_state lnm_http_loop_state_first_res =
|
||||
|
@ -29,10 +32,15 @@ void lnm_http_loop_process_parse_req(lnm_http_conn *conn) {
|
|||
// If the request is already the size of the read buffer, we close the
|
||||
// request. Otherwise, we wait for anything read
|
||||
if (conn->r.size - conn->r.read == LNM_LOOP_BUF_SIZE) {
|
||||
lnm_linfo(section, "Received request larger than buffer (%i bytes)",
|
||||
LNM_LOOP_BUF_SIZE);
|
||||
|
||||
conn->state = lnm_loop_state_end;
|
||||
}
|
||||
break;
|
||||
case lnm_http_parse_err_invalid:
|
||||
lnm_linfo(section, "%s", "Received invalid request");
|
||||
|
||||
conn->state = lnm_loop_state_end;
|
||||
break;
|
||||
case lnm_http_parse_err_unknown_method:
|
||||
|
@ -40,6 +48,10 @@ void lnm_http_loop_process_parse_req(lnm_http_conn *conn) {
|
|||
ctx->state = lnm_http_loop_state_first_res;
|
||||
break;
|
||||
}
|
||||
|
||||
lnm_linfo(section, "%s %.*s HTTP/1.%i",
|
||||
lnm_http_method_names[ctx->req.method], (int)ctx->req.path.len,
|
||||
ctx->req.path.s, ctx->req.minor_version);
|
||||
}
|
||||
|
||||
void lnm_http_loop_process_route(lnm_http_conn *conn) {
|
||||
|
@ -163,6 +175,13 @@ void lnm_http_loop_state_process_add_headers(lnm_http_conn *conn) {
|
|||
false);
|
||||
}
|
||||
|
||||
if (res->status == 0) {
|
||||
res->status = lnm_http_status_ok;
|
||||
}
|
||||
|
||||
lnm_linfo(section, "%i %s", res->status,
|
||||
lnm_http_status_names[res->status / 100 - 1][res->status % 100]);
|
||||
|
||||
ctx->state = lnm_http_loop_state_write_status_line;
|
||||
}
|
||||
|
||||
|
@ -172,10 +191,6 @@ void lnm_http_loop_process_write_status_line(lnm_http_conn *conn) {
|
|||
lnm_http_loop_ctx *ctx = conn->ctx;
|
||||
lnm_http_res *res = &ctx->res;
|
||||
|
||||
if (res->status == 0) {
|
||||
res->status = lnm_http_status_ok;
|
||||
}
|
||||
|
||||
const char *response_type_name =
|
||||
lnm_http_status_names[res->status / 100 - 1][res->status % 100];
|
||||
|
||||
|
|
|
@ -6,8 +6,11 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "lnm/common.h"
|
||||
#include "lnm/log.h"
|
||||
#include "lnm/loop_internal.h"
|
||||
|
||||
static const char *section = "loop";
|
||||
|
||||
lnm_err lnm_loop_init(lnm_loop **out, void *gctx,
|
||||
lnm_err (*ctx_init)(void **out, void *gctx),
|
||||
void (*ctx_free)(void *ctx),
|
||||
|
@ -34,6 +37,8 @@ lnm_err lnm_loop_accept(lnm_loop *l) {
|
|||
int conn_fd = accept(l->listen_fd, NULL, NULL);
|
||||
|
||||
if (conn_fd < 0) {
|
||||
lnm_lcritical(section, "accept failed: %i", conn_fd);
|
||||
|
||||
return lnm_err_failed_network;
|
||||
}
|
||||
|
||||
|
@ -72,6 +77,8 @@ lnm_err lnm_loop_accept(lnm_loop *l) {
|
|||
|
||||
l->conns.open++;
|
||||
|
||||
lnm_ldebug(section, "connection opened with fd %i", conn_fd);
|
||||
|
||||
return lnm_err_ok;
|
||||
}
|
||||
|
||||
|
@ -130,6 +137,8 @@ lnm_err lnm_loop_run(lnm_loop *l) {
|
|||
poll_args[0].fd = l->listen_fd;
|
||||
poll_args[0].events = POLLIN;
|
||||
|
||||
lnm_linfo(section, "started on fd %i", l->listen_fd);
|
||||
|
||||
while (1) {
|
||||
nfds_t poll_args_len = 1;
|
||||
|
||||
|
@ -171,6 +180,8 @@ lnm_err lnm_loop_run(lnm_loop *l) {
|
|||
close(conn->fd);
|
||||
|
||||
l->conns.open--;
|
||||
lnm_ldebug(section, "connection closed with fd %i", conn->fd);
|
||||
|
||||
lnm_loop_conn_free(l, conn);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue