stuff
This commit is contained in:
parent
a0d85d1c71
commit
a06f9f10a0
5 changed files with 38 additions and 11 deletions
|
|
@ -215,7 +215,7 @@ SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
|
||||||
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
|
||||||
NB = $(words $(SRC_BASE))
|
NB = $(words $(SRC_BASE))
|
||||||
INDEX = 0
|
INDEX = 0
|
||||||
SHELL := bash
|
SHELL := /bin/bash
|
||||||
|
|
||||||
all :
|
all :
|
||||||
@$(MAKE) -j $(NAME)
|
@$(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]}"))
|
@$(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/^.*\///')"
|
@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 $@\
|
@$(CC) $(FLAGS) -MMD -c $< -o $@\
|
||||||
-I $(INC_DIR)
|
-I $(INC_DIR) -lm
|
||||||
@$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
|
@$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** DEBUG with no malloc
|
** DEBUG with malloc
|
||||||
*/
|
*/
|
||||||
# define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
|
# define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
|
||||||
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
|
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
int create_server(int port, int backlog, char *protoname);
|
int create_server(int port, int backlog, char *protoname);
|
||||||
int create_client(char *addr, int port, 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_send(int sock, char *msg, int size);
|
||||||
int net_get(int sock, char *msg, int size);
|
int net_get(int sock, char *msg, int size);
|
||||||
|
|
|
||||||
|
|
@ -16,3 +16,28 @@ int create_client(char *addr, int port, char *protoname)
|
||||||
return (-1);
|
return (-1);
|
||||||
return (sock);
|
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);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
double sqrt(double x);
|
||||||
struct s_stats g_rs = {0, 0, 0, 0, 0, 0, 0};
|
struct s_stats g_rs = {0, 0, 0, 0, 0, 0, 0};
|
||||||
|
|
||||||
void rs_clear()
|
void rs_clear()
|
||||||
|
|
@ -32,8 +33,8 @@ void rs_push(double n)
|
||||||
|
|
||||||
void rs_calcmore()
|
void rs_calcmore()
|
||||||
{
|
{
|
||||||
void *libm;
|
/* void *libm; */
|
||||||
double (*sqrt)(double);
|
/* double (*sqrt)(double); */
|
||||||
|
|
||||||
if (g_rs.count == 0)
|
if (g_rs.count == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -47,10 +48,10 @@ void rs_calcmore()
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
g_rs.var = g_rs.m / (g_rs.count - 1);
|
g_rs.var = g_rs.m / (g_rs.count - 1);
|
||||||
if ((libm = dlopen("libm.dylib", 0)) == NULL)
|
/* if ((libm = dlopen("libm.dylib", 0)) == NULL) */
|
||||||
printf("%s\n", dlerror());
|
/* printf("%s\n", dlerror()); */
|
||||||
else if ((sqrt = dlsym(libm, "sqrt")) == NULL)
|
/* else if ((sqrt = dlsym(libm, "sqrt")) == NULL) */
|
||||||
printf("%s\n", dlerror());
|
/* printf("%s\n", dlerror()); */
|
||||||
else
|
/* else */
|
||||||
g_rs.stdev = sqrt(g_rs.var);
|
g_rs.stdev = sqrt(g_rs.var);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue