feat: added basic logging
This commit is contained in:
parent
32687e0b49
commit
5dc772e507
3 changed files with 76 additions and 5 deletions
|
|
@ -11,6 +11,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "event_loop_internal.h"
|
||||
#include "log.h"
|
||||
#include "picohttpparser.h"
|
||||
|
||||
static int event_loop_fd_set_nb(int fd) {
|
||||
|
|
@ -97,7 +98,7 @@ void event_loop_run(event_loop *el, int port) {
|
|||
int fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (fd < 0) {
|
||||
return;
|
||||
critical(1, "Failed to open listening socket, errno: %i", errno);
|
||||
}
|
||||
|
||||
int val = 1;
|
||||
|
|
@ -111,20 +112,24 @@ void event_loop_run(event_loop *el, int port) {
|
|||
int res = bind(fd, (const struct sockaddr *)&addr, sizeof(addr));
|
||||
|
||||
if (res) {
|
||||
return;
|
||||
critical(1, "Failed to bind listening socket, errno: %i", errno);
|
||||
}
|
||||
|
||||
debug("Listening socket bound to fd %i", fd);
|
||||
|
||||
res = listen(fd, SOMAXCONN);
|
||||
|
||||
if (res) {
|
||||
return;
|
||||
critical(1, "Failed to start listening on listening socket, errno: %i",
|
||||
errno);
|
||||
}
|
||||
|
||||
// The listening socket is always poll'ed in non-blocking mode as well
|
||||
res = event_loop_fd_set_nb(fd);
|
||||
|
||||
if (res != 0) {
|
||||
return;
|
||||
critical(1, "Failed to set listening socket to non-blocking, errno: %i",
|
||||
errno);
|
||||
}
|
||||
|
||||
// TODO don't hardcode the number 32
|
||||
|
|
@ -138,6 +143,8 @@ void event_loop_run(event_loop *el, int port) {
|
|||
event_loop_conn *conn;
|
||||
int events;
|
||||
|
||||
info("Starting event loop on port %i", port);
|
||||
|
||||
while (1) {
|
||||
poll_args_count = 1;
|
||||
|
||||
|
|
@ -165,8 +172,9 @@ void event_loop_run(event_loop *el, int port) {
|
|||
// poll for active fds
|
||||
// the timeout argument doesn't matter here
|
||||
int rv = poll(poll_args, (nfds_t)poll_args_count, 1000);
|
||||
|
||||
if (rv < 0) {
|
||||
return;
|
||||
critical(1, "Poll failed, errno: %i", errno);
|
||||
}
|
||||
|
||||
// process active connections
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue