/* ************************************************************************** */ /* */ /* ::: o_ :::::: ::: */ /* server.c :+: / :+::+: :+: */ /* +:+ > +:++:+ +:+ */ /* By: whaffman +#+ +:+ +#++#++:++#++ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */ /* Created: 2024/07/18 17:24:54 by whaffman #+#+# #+#+# #+# #+# | */ /* Updated: 2024/07/27 18:23:52 by whaffman ### ### ### ### / \ */ /* */ /* ************************************************************************** */ #include #include #include #include "libft/libft.h" void signal_handler(int signum, siginfo_t *info, void *context) { static int count = 0; static char c = '\0'; static pid_t client_pid; (void) context; if (client_pid != info->si_pid) { count = 0; c = '\0'; client_pid = info->si_pid; } count++; if (signum == SIGUSR1) c |= 1 << (8 - count); if (count == 8) { if (c) write(1, &c, 1); else write(1, "\n", 1); c = '\0'; count = 0; } kill(info->si_pid, SIGUSR1); return ; } int main(void) { struct sigaction sa; 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; sigaction(SIGUSR1, &sa, NULL); sigaction(SIGUSR2, &sa, NULL); while (1) pause(); }