-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.c
More file actions
57 lines (52 loc) · 1.62 KB
/
Copy pathserver.c
File metadata and controls
57 lines (52 loc) · 1.62 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hceviz <hceviz@student.42warsaw.pl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/01 12:33:30 by hceviz #+# #+# */
/* Updated: 2025/02/02 22:07:39 by hceviz ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
//be careful with arguments quotation marks
void handler(int signal, siginfo_t *info, void *ucontext)
{
static int bitcount;
static char chr;
(void)info;
(void)ucontext;
if (signal == SIGUSR2)
chr = (chr << 1) | 1;
else if (signal == SIGUSR1)
chr = (chr << 1);
bitcount++;
if (bitcount == 8)
{
bitcount = 0;
if (chr == '\0')
{
write(1, "\n", 1);
chr = 0;
return ;
}
write(1, &chr, 1);
chr = 0;
}
}
int main(void)
{
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGUSR2);
sigaddset(&sa.sa_mask, SIGUSR1);
sa.sa_flags = 0;
sa.sa_sigaction = handler;
sigaction(SIGUSR2, &sa, NULL);
sigaction(SIGUSR1, &sa, NULL);
ft_printf("PID=%d\n", getpid());
while (1)
;
return (1);
}