Add preliminary support for options

This commit is contained in:
Kamil Trzcinski
2022-04-05 16:52:12 +02:00
parent 4ac1a8dbe5
commit 97055565b5
6 changed files with 153 additions and 19 deletions

View File

@ -14,7 +14,7 @@
#define BUFSIZE 256
static int http_listen(int listen_port, int maxcons)
static int http_listen(int port, int maxcons)
{
struct sockaddr_in server = {0};
int listenfd = -1;
@ -22,7 +22,7 @@ static int http_listen(int listen_port, int maxcons)
// getaddrinfo for host
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(listen_port);
server.sin_port = htons(port);
listenfd = socket(AF_INET, SOCK_STREAM, 0);
if (listenfd < 0) {
@ -124,7 +124,7 @@ error:
int http_server(http_server_options_t *options, http_method_t *methods)
{
int listen_fd = http_listen(options->listen_port, options->maxcons);
int listen_fd = http_listen(options->port, options->maxcons);
if (listen_fd < 0) {
return -1;
}
@ -133,7 +133,7 @@ int http_server(http_server_options_t *options, http_method_t *methods)
for (int worker = 0; worker < options->maxcons; worker++) {
char name[20];
sprintf(name, "HTTP%d/%d", options->listen_port, worker);
sprintf(name, "HTTP%d/%d", options->port, worker);
http_worker_t *worker = calloc(1, sizeof(http_worker_t));
worker->name = strdup(name);

View File

@ -29,7 +29,7 @@ typedef struct http_worker_s {
} http_worker_t;
typedef struct http_server_options_s {
int listen_port;
int port;
int maxcons;
} http_server_options_t;