diff --git a/libft/Makefile b/libft/Makefile index 060feedc..0b7088f5 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -215,7 +215,7 @@ SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o)) NB = $(words $(SRC_BASE)) INDEX = 0 -SHELL := bash +SHELL := /bin/bash all : @$(MAKE) -j $(NAME) @@ -235,7 +235,7 @@ $(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR) @$(eval COLOR=$(shell list=(160 196 202 208 215 221 226 227 190 154 118 82 46); index=$$(($(PERCENT) * $${#list[@]} / 100)); echo "$${list[$$index]}")) @printf "\r\033[38;5;%dm⌛ [%s]: %2d%% `printf '█%.0s' {0..$(DONE)}`%*s❙%*.*s\033[0m\033[K" $(COLOR) $(NAME) $(PERCENT) $(TO_DO) "" $(DELTA) $(DELTA) "$(shell echo "$@" | sed 's/^.*\///')" @$(CC) $(FLAGS) -MMD -c $< -o $@\ - -I $(INC_DIR) + -I $(INC_DIR) -lm @$(eval INDEX=$(shell echo $$(($(INDEX)+1)))) clean : diff --git a/libft/includes/error.h b/libft/includes/error.h index 64f16559..3780ad8f 100644 --- a/libft/includes/error.h +++ b/libft/includes/error.h @@ -17,7 +17,7 @@ # include /* -** DEBUG with no malloc +** DEBUG with malloc */ # define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}" # define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__ diff --git a/libft/includes/net.h b/libft/includes/net.h index c339753b..f6add720 100644 --- a/libft/includes/net.h +++ b/libft/includes/net.h @@ -11,6 +11,7 @@ int create_server(int port, int backlog, char *protoname); int create_client(char *addr, int port, char *protoname); +void listener(int domain, int sock, int proto, void (*handler)(void *buf, int bytes, struct sockaddr_in *addr)); int net_send(int sock, char *msg, int size); int net_get(int sock, char *msg, int size); diff --git a/libft/srcs/net/create_client.c b/libft/srcs/net/create_client.c index 77411380..dfc2628a 100644 --- a/libft/srcs/net/create_client.c +++ b/libft/srcs/net/create_client.c @@ -16,3 +16,28 @@ int create_client(char *addr, int port, char *protoname) return (-1); return (sock); } + +void listener(int domain, int sock, int proto, void (*handler)(void *buf, int bytes, struct sockaddr_in *addr)) +{ int sd; + struct sockaddr_in addr; + unsigned char buf[1024]; + + sd = socket(domain, sock, proto); + if (sd < 0) + { + perror("listener socket"); + exit(0); + } + for (;;) + { int bytes; + socklen_t len=sizeof(addr); + + bzero(buf, sizeof(buf)); + bytes = recvfrom(sd, buf, sizeof(buf), 0, (struct sockaddr*)&addr, &len); + if (bytes > 0 && handler) + handler(buf, bytes, &addr); + else + perror("recvfrom"); + } + exit(0); +} diff --git a/libft/srcs/rs/rs.c b/libft/srcs/rs/rs.c index 3f738785..3cddd3ef 100644 --- a/libft/srcs/rs/rs.c +++ b/libft/srcs/rs/rs.c @@ -1,6 +1,7 @@ #include "libft.h" #include +double sqrt(double x); struct s_stats g_rs = {0, 0, 0, 0, 0, 0, 0}; void rs_clear() @@ -32,8 +33,8 @@ void rs_push(double n) void rs_calcmore() { - void *libm; - double (*sqrt)(double); + /* void *libm; */ + /* double (*sqrt)(double); */ if (g_rs.count == 0) { @@ -47,10 +48,10 @@ void rs_calcmore() return ; } g_rs.var = g_rs.m / (g_rs.count - 1); - if ((libm = dlopen("libm.dylib", 0)) == NULL) - printf("%s\n", dlerror()); - else if ((sqrt = dlsym(libm, "sqrt")) == NULL) - printf("%s\n", dlerror()); - else - g_rs.stdev = sqrt(g_rs.var); + /* if ((libm = dlopen("libm.dylib", 0)) == NULL) */ + /* printf("%s\n", dlerror()); */ + /* else if ((sqrt = dlsym(libm, "sqrt")) == NULL) */ + /* printf("%s\n", dlerror()); */ + /* else */ + g_rs.stdev = sqrt(g_rs.var); }