-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_bonus.c
54 lines (49 loc) · 1.54 KB
/
server_bonus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amait-ou <amait-ou@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/30 12:29:45 by amait-ou #+# #+# */
/* Updated: 2023/01/01 14:53:10 by amait-ou ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk_bonus.h"
static void ft_server(int signo, siginfo_t *sig_info, void *context)
{
static int i;
static char ascii;
static int g_pid;
(void)context;
signo -= SIGUSR1;
if (g_pid != sig_info->si_pid)
{
ascii = 0;
i = 0;
g_pid = sig_info->si_pid;
}
ascii += signo * ft_power(2, (7 - i));
++i;
if (i == 8)
{
if (ascii == 0)
kill(sig_info->si_pid, SIGUSR1);
ft_putchar(ascii);
i = 0;
ascii = 0;
}
}
int main(void)
{
struct sigaction sa;
sa.sa_sigaction = ft_server;
ft_putnbr(getpid());
ft_putchar('\n');
sa.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
while (1)
pause();
return (0);
}