-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.c
54 lines (49 loc) · 1.51 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lantonio <lantonio@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/31 09:33:48 by lantonio #+# #+# */
/* Updated: 2024/07/31 09:40:55 by lantonio ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void stoc(int bit, siginfo_t *info, void *context)
{
static int i = 0;
static int c = 0;
c = c * 2;
(void)context;
if (bit == SIGUSR1)
c = c + 1;
i++;
if (i == 8)
{
write(1, &c, 1);
if (c == '\0')
write(1, "\n", 1);
i = 0;
c = 0;
}
if (kill(info->si_pid, SIGUSR1) == -1)
{
ft_printf("408 Request Timeout\n");
c = 0;
i = 0;
}
}
int main(void)
{
struct sigaction s_c;
s_c.sa_sigaction = stoc;
s_c.sa_flags = SA_SIGINFO;
sigemptyset(&s_c.sa_mask);
sigaction(SIGUSR1, &s_c, NULL);
sigaction(SIGUSR2, &s_c, NULL);
ft_printf("Server PID = %d\n", getpid());
while (1)
pause();
return (0);
}