/* ************************************************************************** */ /* */ /* ::: o_ :::::: ::: */ /* server.c :+: / :+::+: :+: */ /* +:+ > +:++:+ +:+ */ /* By: whaffman +#+ +:+ +#++#++:++#++ */ /* +#+ +#+#+ +#++#+ +#+ \o/ */ /* Created: 2024/07/18 17:24:54 by whaffman #+#+# #+#+# #+# #+# | */ /* Updated: 2024/07/27 14:40:08 by whaffman ### ### ### ### / \ */ /* */ /* ************************************************************************** */ #include #include #include void ft_putstr(char *str) { int i; i = 0; while (str[i]) { i++; } write(1, str, i); } 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; } c = c << 1; if (signum == SIGUSR1) c |= 1; 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; printf("MiniTalk Server started on pid: %d\n", getpid()); 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(); }