-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.c
73 lines (66 loc) · 1.77 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
64
65
66
67
68
69
70
71
72
73
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bschwitz <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/15 13:24:28 by bschwitz #+# #+# */
/* Updated: 2022/02/17 16:02:19 by bschwitz ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
int g_server_on = 1;
static void print_pid(void)
{
pid_t pid_num;
pid_num = getpid();
if (pid_num == 0)
return ;
write(STDOUT_FILENO, "PID : ", 7);
ft_putnbr_fd(pid_num, 1);
write(STDOUT_FILENO, "\n", 2);
}
static void reception(int sig)
{
static size_t i;
static int bit;
static char buf[1000000];
if (--bit == -1)
{
bit = 6;
++i;
}
buf[i] &= ~(1 << 7);
if (sig == SIGUSR1)
buf[i] |= (1 << bit);
else if (sig == SIGUSR2)
buf[i] &= ~(1 << bit);
if (i == 999999 || buf[i] == 127)
{
buf[i] = 0;
write(STDOUT_FILENO, buf, i + 1);
ft_memset(buf, '\0', 999999);
i = 0;
bit = 0;
}
}
int main(int argc, char **argv)
{
argv = NULL;
if (argc != 1)
{
write (STDERR_FILENO, "Executez uniquement ./server.\n", 31);
return (1);
}
else
{
print_pid();
signal(SIGUSR1, reception);
signal(SIGUSR2, reception);
while (g_server_on)
{
}
}
return (0);
}