-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_server.c
53 lines (48 loc) · 1.55 KB
/
ft_server.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbesan <mbesan@student.21-school.ru> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/01 15:44:48 by mbesan #+# #+# */
/* Updated: 2021/11/09 17:54:10 by mbesan ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
#include <unistd.h>
#include "libft/libft.h"
static void sig_handler(int signum, siginfo_t *siginfo, void *context)
{
static int bytes;
static unsigned char symbol;
(void)context;
symbol |= (signum == SIGUSR2);
if (++bytes == 8)
{
bytes = 0;
if (!symbol)
{
kill(siginfo->si_pid, SIGUSR1);
return ;
}
ft_putchar_fd(symbol, 1);
symbol = 0;
kill(siginfo->si_pid, SIGUSR2);
}
else
symbol <<= 1;
}
int main(void)
{
struct sigaction act;
ft_putnbr_fd(getpid(), 1);
write(1, "\n", 1);
act.sa_sigaction = sig_handler;
act.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &act, 0);
sigaction(SIGUSR2, &act, 0);
while (1)
pause();
return (0);
}