style: add comments

This commit is contained in:
2025-12-01 22:47:16 +01:00
parent f08e17d8c8
commit bc8568f926
7 changed files with 82 additions and 67 deletions

View File

@@ -9,26 +9,29 @@
#include "core/worker.h"
#include "utils/error.h"
/* Clients max queue */
/* Maximum queue of pending client connections */
#define CWS_SERVER_BACKLOG 128
/* Size of the epoll_event array */
/* Max number of epoll events processed per iteration */
#define CWS_SERVER_EPOLL_MAXEVENTS 64
/* Blocking timeout for epoll_wait in ms */
#define CWS_SERVER_EPOLL_TIMEOUT 3000
/* Maximum allowed HTTP request size */
#define CWS_SERVER_MAX_REQUEST_SIZE (16 * 1024) /* 16KB */
/* Number of worker threads */
#define CWS_WORKERS_NUM 6
/* Main server loop */
/* Global flag used to stop server */
extern volatile sig_atomic_t cws_server_run;
typedef struct cws_server {
int epfd;
int sockfd;
cws_worker_s **workers;
cws_config_s *config;
int epfd; /* epoll instance for incoming connections */
int sockfd; /* listening socket */
cws_worker_s **workers; /* worker thread pool */
cws_config_s *config; /* config pointer */
} cws_server_s;
cws_return cws_server_setup(cws_server_s *server, cws_config_s *config);

View File

@@ -7,11 +7,16 @@
#include "config/config.h"
/* Blocking timeout for epoll_wait in ms */
#define WORKER_EPOLL_TIMEOUT 250
/* Max number of epoll events processed per iteration */
#define WORKER_EPOLL_MAX_EVENTS 64
extern volatile sig_atomic_t cws_server_run;
typedef struct cws_worker {
int epfd;
size_t clients_num;
pthread_t thread;
cws_config_s *config;
} cws_worker_s;

View File

@@ -22,14 +22,12 @@
#endif
#ifdef EVELOPER
#define CWS_LOG_DEBUG(msg, ...) \
fprintf(stdout, _DEBUG " [%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#define CWS_LOG_DEBUG(msg, ...) fprintf(stdout, _DEBUG " [%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define CWS_LOG_DEBUG(msg, ...)
#endif
#define CWS_LOG_ERROR(msg, ...) \
fprintf(stderr, _ERR " [%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#define CWS_LOG_ERROR(msg, ...) fprintf(stderr, _ERR " [%s:%d] " msg "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#define CWS_LOG_WARNING(msg, ...) fprintf(stdout, _WARNING " " msg "\n", ##__VA_ARGS__)
#define CWS_LOG_INFO(msg, ...) fprintf(stdout, _INFO " " msg "\n", ##__VA_ARGS__)