From 1c6b660be03788b3f72afe52c1efdda92e005ead Mon Sep 17 00:00:00 2001 From: Willem Haffmans Date: Sat, 27 Jul 2024 18:47:04 +0200 Subject: [PATCH] norm :25lines --- client.c | 52 ++++------------------------------------------------ server.c | 13 +++++++------ 2 files changed, 11 insertions(+), 54 deletions(-) diff --git a/client.c b/client.c index e4ac751..a9e5e44 100644 --- a/client.c +++ b/client.c @@ -6,62 +6,18 @@ /* By: whaffman +#+ +:+ +#++#++:++#++ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */ /* Created: 2024/07/18 16:28:03 by whaffman #+#+# #+#+# #+# #+# | */ -/* Updated: 2024/07/27 14:43:17 by whaffman ### ### ### ### / \ */ +/* Updated: 2024/07/27 18:40:57 by whaffman ### ### ### ### / \ */ /* */ /* ************************************************************************** */ #include #include -#define SLEEP 100 +#include "libft/libft.h" + +#define SLEEP 300 static volatile int g_ack = 0; -size_t ft_strlen(const char *s) -{ - size_t length; - - length = 0; - while (*s++) - length++; - return (length); -} - -void ft_putstr(char *str) -{ - write(1, str, ft_strlen(str)); -} - -int ft_isspace(int c) -{ - return (' ' == c || '\f' == c || '\n' == c - || '\r' == c || '\t' == c || '\v' == c); -} - -int ft_isdigit(char c) -{ - return (c >= '0' && c <= '9'); -} - -int ft_atoi(const char *nptr) -{ - int sign; - int res; - - while (ft_isspace(*nptr)) - nptr++; - res = 0; - sign = 1; - while (*nptr == '-' || *nptr == '+') - { - if (*nptr == '-') - sign *= -1; - nptr++; - } - while (ft_isdigit(*nptr)) - res = 10 * res + sign * (*nptr++ - '0'); - return (res); -} - int send_byte(int pid, unsigned char c) { int i; diff --git a/server.c b/server.c index d1b0ec8..3c5cf86 100644 --- a/server.c +++ b/server.c @@ -6,14 +6,14 @@ /* By: whaffman +#+ +:+ +#++#++:++#++ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */ /* Created: 2024/07/18 17:24:54 by whaffman #+#+# #+#+# #+# #+# | */ -/* Updated: 2024/07/27 15:04:43 by whaffman ### ### ### ### / \ */ +/* Updated: 2024/07/27 18:23:52 by whaffman ### ### ### ### / \ */ /* */ /* ************************************************************************** */ #include #include #include -#include "libft.h" +#include "libft/libft.h" void signal_handler(int signum, siginfo_t *info, void *context) { @@ -28,10 +28,9 @@ void signal_handler(int signum, siginfo_t *info, void *context) c = '\0'; client_pid = info->si_pid; } - c = c << 1; - if (signum == SIGUSR1) - c |= 1; count++; + if (signum == SIGUSR1) + c |= 1 << (8 - count); if (count == 8) { if (c) @@ -49,7 +48,9 @@ int main(void) { struct sigaction sa; - printf("MiniTalk Server started on pid: %d\n", getpid()); + ft_putstr("MiniTalk Server started on pid: "); + ft_putnbr(getpid()); + ft_putstr("\n"); sa.sa_sigaction = signal_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_SIGINFO;