-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.c
executable file
·51 lines (45 loc) · 1.5 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fvieira <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/09 15:44:23 by fvieira #+# #+# */
/* Updated: 2022/12/13 17:39:31 by fvieira ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void handler(int signal)
{
static int counter = 0;
static unsigned char bin = 0;
unsigned char bit;
bit = (signal == SIGUSR1);
bin |= (bit << counter);
counter++;
if (counter == 8)
{
ft_putchar_fd(bin, 1);
bin = 0;
counter = 0;
}
}
void signaltreatment(void)
{
struct sigaction action;
action.sa_handler = &handler;
action.sa_flags = SA_SIGINFO;
if (sigaction(SIGUSR1, &action, NULL) == -1)
exit(1);
if (sigaction(SIGUSR2, &action, NULL) == -1)
exit(1);
}
int main(void)
{
ft_printf("Boring message to tell you pid = %d\n", getpid());
signaltreatment();
while (1)
pause();
return (0);
}