refactor(server): clean code
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
#include "utils/utils.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
volatile sig_atomic_t cws_server_run = 1;
|
||||
|
||||
static void cws_utils_convert_ip(int family, void *addr, char *ip, size_t ip_len) { inet_ntop(family, addr, ip, ip_len); }
|
||||
|
||||
void cws_utils_get_client_ip(struct sockaddr_storage *sa, char *ip) {
|
||||
@@ -17,6 +21,16 @@ void cws_utils_get_client_ip(struct sockaddr_storage *sa, char *ip) {
|
||||
}
|
||||
}
|
||||
|
||||
cws_server_ret cws_fd_set_nonblocking(int sockfd) {
|
||||
const int status = fcntl(sockfd, F_SETFL, O_NONBLOCK);
|
||||
|
||||
if (status == -1) {
|
||||
return CWS_SERVER_FD_NONBLOCKING_ERROR;
|
||||
}
|
||||
|
||||
return CWS_SERVER_OK;
|
||||
}
|
||||
|
||||
unsigned int my_str_hash_fn(const void *key) {
|
||||
char *key_str = (char *)key;
|
||||
size_t key_len = strlen(key_str);
|
||||
@@ -55,6 +69,6 @@ bool my_int_equal_fn(const void *a, const void *b) {
|
||||
|
||||
void my_int_free_key_fn(void *key) {
|
||||
int fd = *(int *)key;
|
||||
close(fd);
|
||||
sock_close(fd);
|
||||
free(key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user