-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.c
58 lines (52 loc) · 1.56 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dalbano <dalbano@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/01 10:53:19 by dalbano #+# #+# */
/* Updated: 2024/11/01 19:17:51 by dalbano ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/libft.h"
#include "printf/ft_printf.h"
#include <signal.h>
#define BUFFER_SIZE 1024
void handle_signal(int sig)
{
static int bit_count = 0;
static char character = 0;
character <<= 1;
if (sig == SIGUSR1)
character |= 1;
bit_count++;
if (bit_count == 8)
{
if (character == '\0')
{
write(1, "\n", 1);
}
else
{
write(1, &character, 1);
}
character = 0;
bit_count = 0;
}
}
int main(void)
{
pid_t pid;
struct sigaction sa;
pid = getpid();
ft_printf("Server PID: %d\n", pid);
sa.sa_handler = handle_signal;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
while (1)
pause();
return (0);
}