-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.c
49 lines (44 loc) · 1.44 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asodor <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/01 00:23:29 by asodor #+# #+# */
/* Updated: 2024/05/05 06:32:04 by asodor ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void signal_handler(int sig)
{
static char character;
static int bits_received;
bits_received++;
character = character << 1;
if (sig == SIGUSR1)
character = character | 1;
if (bits_received == 8)
{
write(1, &character, 1);
bits_received = 0;
character = 0;
}
}
int main(void)
{
struct sigaction sa;
pid_t pid;
pid = getpid();
ft_putstr("Server PID : ");
ft_putnbr((long)pid);
ft_putstr("\n");
sa.sa_handler = &signal_handler;
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
while (1)
{
pause();
}
return (0);
}