-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.c
63 lines (57 loc) · 1.72 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
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tanas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/28 22:51:26 by tanas #+# #+# */
/* Updated: 2023/06/15 15:58:09 by tanas ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
/*
SIGUSR1 == 1;
SIGUSR2 == 0;
*/
static void sigusr_handler(int signum, siginfo_t *info, void *context)
{
static char c;
static int bits;
(void) context;
(void) info;
c |= (signum == SIGUSR1);
bits++;
if (bits == 8)
{
ft_printf("%c", c);
bits = 0;
c = 0;
kill(info->si_pid, SIGUSR1);
}
c <<= 1;
if (signum == SIGINT)
{
ft_printf(B_MAGENTA"\nServer shutting down.\n"RESET);
exit(4);
}
}
// server
int main(int argc, char **argv)
{
struct sigaction act;
(void) argv;
if (argc != 1)
{
ft_printf(BI_RED"\nError! Invalid number of arguments entered.\n\n"RESET);
exit(0);
}
act.sa_flags = SA_SIGINFO;
act.sa_sigaction = sigusr_handler;
sigaction(SIGUSR1, &act, NULL);
sigaction(SIGUSR2, &act, NULL);
sigaction(SIGINT, &act, NULL);
ft_printf(B_CYAN"SERVER PID: %i\n"RESET, getpid());
while (1)
pause();
}