diff --git a/Makefile b/Makefile index 15ff0c2..18d30a9 100644 --- a/Makefile +++ b/Makefile @@ -28,16 +28,14 @@ C_DEPS = ./includes/client.h # rules to execute # recipe | $< : 1st prerequisite # - - - - - - - - - - - - - - # recipe | $^ : all prerequisites -all: libft $(S_NAME) $(C_NAME) - -libft: - @echo "hello" - make -C $(LDIR) +all: $(S_NAME) $(C_NAME) $(S_NAME): $(S_OBJS) $(S_DEPS) + make -C $(LDIR) $(CC) $(CFLAGS) -o $@ $< $(LFLAGS) $(C_NAME): $(C_OBJS) $(C_DEPS) + make -C $(LDIR) $(CC) $(CFLAGS) -o $@ $< $(LFLAGS) $(ODIR)/%.o: %.c | $(ODIR) @@ -55,6 +53,7 @@ clean: /bin/rm -f $(S_OBJS) $(C_OBJS) fclean: clean + make fclean -C $(LDIR) /bin/rm -rf $(ODIR) /bin/rm -f $(S_NAME) $(C_NAME) /bin/rm -rf a.out a.out.dSYM diff --git a/builds/client.o b/builds/client.o deleted file mode 100644 index 5a8902d..0000000 Binary files a/builds/client.o and /dev/null differ diff --git a/builds/server.o b/builds/server.o deleted file mode 100644 index 7664bf4..0000000 Binary files a/builds/server.o and /dev/null differ diff --git a/client b/client deleted file mode 100755 index 8897c41..0000000 Binary files a/client and /dev/null differ diff --git a/includes/client.h b/includes/client.h index 2d38dcd..81a3859 100644 --- a/includes/client.h +++ b/includes/client.h @@ -15,7 +15,7 @@ typedef struct s_client int done; } t_client; -t_client client; +t_client g_client; #endif diff --git a/includes/server.h b/includes/server.h index 03898e1..8f67d9f 100644 --- a/includes/server.h +++ b/includes/server.h @@ -6,13 +6,12 @@ # include // for getpid # include "libft.h" -typedef struct s_message +typedef struct s_server { unsigned int count_bits; char character; - char *text; -} t_message; +} t_server; -t_message message; +t_server g_server; #endif diff --git a/libft b/libft deleted file mode 120000 index 4aa6356..0000000 --- a/libft +++ /dev/null @@ -1 +0,0 @@ -../../libft \ No newline at end of file diff --git a/libft b/libft new file mode 160000 index 0000000..c335eb1 --- /dev/null +++ b/libft @@ -0,0 +1 @@ +Subproject commit c335eb1f6a77f1db972c9f984962836c476d7e70 diff --git a/server b/server deleted file mode 100755 index 47f8cc3..0000000 Binary files a/server and /dev/null differ diff --git a/srcs/client.c b/srcs/client.c index 85a543c..b0c37e2 100644 --- a/srcs/client.c +++ b/srcs/client.c @@ -2,7 +2,7 @@ int usage(void) { - ft_printf("usage: ./client [server pid] [message]\n"); + ft_putstr("usage: ./client [server pid] [message]\n"); return (0); } @@ -17,25 +17,25 @@ void send_char(char c, int mask, int server_pid) void send_message(int sig_num) { (void)sig_num; - client.mask >>= 1; - if (client.mask == 0) + g_client.mask >>= 1; + if (g_client.mask == 0) { - client.mask = 1 << 6; - if (client.text[client.count_char] == '\0') - client.done = 1; - (client.count_char)++; + g_client.mask = 1 << 6; + if (g_client.text[g_client.count_char] == '\0') + g_client.done = 1; + (g_client.count_char)++; } - if (client.done == 0) - send_char(client.text[client.count_char], client.mask, client.srv_pid); + if (g_client.done == 0) + send_char(g_client.text[g_client.count_char], g_client.mask, g_client.srv_pid); } void init_client(int pid, char *msg) { - client.mask = 1 << 7; - client.count_char = 0; - client.srv_pid = pid; - client.text = msg; - client.done = 0; + g_client.mask = 1 << 7; + g_client.count_char = 0; + g_client.srv_pid = pid; + g_client.text = msg; + g_client.done = 0; } int main(int ac, char **av) @@ -45,7 +45,7 @@ int main(int ac, char **av) return (usage()); init_client(ft_atoi(av[1]), av[2]); kill((int)getpid(), SIGUSR1); - while (client.done == 0) + while (g_client.done == 0) ; return (0); } diff --git a/srcs/server.c b/srcs/server.c index ce9a575..820686a 100644 --- a/srcs/server.c +++ b/srcs/server.c @@ -2,11 +2,11 @@ void send_char(void) { - if (message.count_bits == 7) + if (g_server.count_bits == 7) { - ft_putchar(message.character); - message.count_bits = 0; - message.character = 0; + ft_putchar(g_server.character); + g_server.count_bits = 0; + g_server.character = 0; } } @@ -14,8 +14,8 @@ void sig_handler_1(int sig_num, siginfo_t *info, void *context) { (void)sig_num; (void)context; - message.character ^= 1 << (6 - message.count_bits); - message.count_bits++; + g_server.character ^= 1 << (6 - g_server.count_bits); + g_server.count_bits++; send_char(); kill(info->si_pid, SIGUSR1); } @@ -24,16 +24,15 @@ void sig_handler_2(int sig_num, siginfo_t *info, void *context) { (void)sig_num; (void)context; - message.count_bits++; + g_server.count_bits++; send_char(); kill(info->si_pid, SIGUSR1); } void init_message(void) { - message.count_bits = 0; - message.character = 0; - message.text = ft_strdup(""); + g_server.count_bits = 0; + g_server.character = 0; } int main(void) @@ -79,15 +78,6 @@ int main(void) ** ** ** # # # # # # # # # # # # # # # # # # # # -** ressources -** -** use of getpid : https://www.includehelp.com/c/getpid-and-getppid-functions-in-c-linux.aspx -** use of signal : https://linuxhint.com/signal_handlers_c_programming_language -** use of sigaction : https://stackoverflow.com/a/17572787/9497573 -** standard signal vs real time signals (with queue option) : https://www.softprayog.in/programming/posix-real-time-signals-in-linux -** -** -** # # # # # # # # # # # # # # # # # # # # ** UNITS PREFIX ** ** times in seconds, deci, centi, milli, micros and nano :