minor checks

This commit is contained in:
2025-08-02 16:33:47 +02:00
parent bcbcb10d1c
commit 997029112b
4 changed files with 12 additions and 9 deletions

1
.gitignore vendored
View File

@@ -3,6 +3,7 @@ build/
docs/ docs/
cert.pem cert.pem
key.pem key.pem
test.md
# Prerequisites # Prerequisites
*.d *.d

View File

@@ -2,8 +2,6 @@
#define CWS_SERVER_H #define CWS_SERVER_H
#include <netdb.h> #include <netdb.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <signal.h> #include <signal.h>
#include <sys/socket.h> #include <sys/socket.h>
@@ -50,10 +48,9 @@ typedef enum cws_server_ret_t {
* @brief Setups hints object * @brief Setups hints object
* *
* @param[out] hints The hints addrinfo * @param[out] hints The hints addrinfo
* @param[in] len The length of hints
* @param[in] hostname The hostname (could be NULL) * @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 * @brief Runs the server

View File

@@ -1,6 +1,8 @@
#include <errno.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "server/server.h" #include "server/server.h"

View File

@@ -4,8 +4,6 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -19,8 +17,8 @@
volatile sig_atomic_t cws_server_run = 1; volatile sig_atomic_t cws_server_run = 1;
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) {
memset(hints, 0, len); memset(hints, 0, sizeof(struct addrinfo));
/* IPv4 or IPv6 */ /* IPv4 or IPv6 */
hints->ai_family = AF_UNSPEC; hints->ai_family = AF_UNSPEC;
@@ -42,7 +40,7 @@ cws_server_ret cws_server_start(cws_config *config) {
struct addrinfo hints; struct addrinfo hints;
struct addrinfo *res; 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); int status = getaddrinfo(config->hostname, config->port, &hints, &res);
if (status != 0) { if (status != 0) {
@@ -120,6 +118,11 @@ cws_server_ret cws_server_loop(int sockfd, cws_config *config) {
while (cws_server_run) { while (cws_server_run) {
int nfds = epoll_wait(epfd, revents, CWS_SERVER_EPOLL_MAXEVENTS, CWS_SERVER_EPOLL_TIMEOUT); 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) { for (int i = 0; i < nfds; ++i) {
if (revents[i].data.fd == sockfd) { if (revents[i].data.fd == sockfd) {
ret = cws_server_handle_new_client(sockfd, epfd, clients); ret = cws_server_handle_new_client(sockfd, epfd, clients);