65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
#ifndef APP_H
|
|
#define APP_H
|
|
|
|
#include "context.h"
|
|
#include "router.h"
|
|
#include "reactor/pool.h"
|
|
#include "reactor/epoll.h"
|
|
#include <sys/types.h>
|
|
|
|
typedef struct app app_t;
|
|
typedef void (*app_handler_t)(context_t *ctx);
|
|
|
|
// Web application
|
|
struct app {
|
|
runtime_t *rt;
|
|
pool_t *pool;
|
|
router_t *router;
|
|
int listen_fd;
|
|
int port;
|
|
|
|
// Configuration
|
|
int max_conns;
|
|
size_t read_buf_size;
|
|
size_t write_buf_size;
|
|
size_t arena_size;
|
|
|
|
// Worker configuration
|
|
int num_workers; // Number of worker processes (0 = single process)
|
|
int cpu_affinity; // Pin workers to CPU cores
|
|
|
|
// Worker management
|
|
pid_t *worker_pids; // Array of worker process IDs
|
|
int worker_id; // Current worker ID (-1 for parent)
|
|
|
|
// Default handlers
|
|
app_handler_t not_found;
|
|
app_handler_t error_handler;
|
|
};
|
|
|
|
// App lifecycle
|
|
app_t* app_new(void);
|
|
void app_free(app_t *a);
|
|
int app_listen(app_t *a, int port);
|
|
int app_run(app_t *a);
|
|
|
|
// Route registration
|
|
void app_get(app_t *a, const char *path, app_handler_t handler);
|
|
void app_post(app_t *a, const char *path, app_handler_t handler);
|
|
void app_put(app_t *a, const char *path, app_handler_t handler);
|
|
void app_delete(app_t *a, const char *path, app_handler_t handler);
|
|
void app_route(app_t *a, const char *method, const char *path, app_handler_t handler);
|
|
|
|
// Configuration
|
|
void app_set_max_conns(app_t *a, int max);
|
|
void app_set_buffer_sizes(app_t *a, size_t read_size, size_t write_size);
|
|
void app_set_arena_size(app_t *a, size_t size);
|
|
void app_set_not_found(app_t *a, app_handler_t handler);
|
|
void app_set_error(app_t *a, app_handler_t handler);
|
|
|
|
// Worker configuration
|
|
void app_set_workers(app_t *a, int num_workers);
|
|
void app_set_cpu_affinity(app_t *a, int enabled);
|
|
|
|
#endif // APP_H
|