diff --git a/.gitignore b/.gitignore index 7922831..1f3680f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build/ docs/ cert.pem key.pem +test.md # Prerequisites *.d diff --git a/include/server/server.h b/include/server/server.h index d63395f..dacc7a0 100644 --- a/include/server/server.h +++ b/include/server/server.h @@ -2,8 +2,6 @@ #define CWS_SERVER_H #include -#include -#include #include #include @@ -50,10 +48,9 @@ typedef enum cws_server_ret_t { * @brief Setups hints object * * @param[out] hints The hints addrinfo - * @param[in] len The length of hints * @param[in] hostname The hostname (could be NULL) */ -void cws_server_setup_hints(struct addrinfo *hints, size_t len, const char *hostname); +void cws_server_setup_hints(struct addrinfo *hints, const char *hostname); /** * @brief Runs the server diff --git a/src/main.c b/src/main.c index d66d2ec..b1f38cc 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,8 @@ +#include #include #include #include +#include #include #include "server/server.h" diff --git a/src/server/server.c b/src/server/server.c index 23f889f..a41034f 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include #include #include @@ -19,8 +17,8 @@ volatile sig_atomic_t cws_server_run = 1; -void cws_server_setup_hints(struct addrinfo *hints, size_t len, const char *hostname) { - memset(hints, 0, len); +void cws_server_setup_hints(struct addrinfo *hints, const char *hostname) { + memset(hints, 0, sizeof(struct addrinfo)); /* IPv4 or IPv6 */ hints->ai_family = AF_UNSPEC; @@ -42,7 +40,7 @@ cws_server_ret cws_server_start(cws_config *config) { struct addrinfo hints; struct addrinfo *res; - cws_server_setup_hints(&hints, sizeof hints, config->hostname); + cws_server_setup_hints(&hints, config->hostname); int status = getaddrinfo(config->hostname, config->port, &hints, &res); if (status != 0) { @@ -120,6 +118,11 @@ cws_server_ret cws_server_loop(int sockfd, cws_config *config) { while (cws_server_run) { int nfds = epoll_wait(epfd, revents, CWS_SERVER_EPOLL_MAXEVENTS, CWS_SERVER_EPOLL_TIMEOUT); + if (nfds == 0) { + CWS_LOG_INFO("epoll timeout, continue..."); + continue; + } + for (int i = 0; i < nfds; ++i) { if (revents[i].data.fd == sockfd) { ret = cws_server_handle_new_client(sockfd, epfd, clients);