-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_bonus.c
58 lines (52 loc) · 1.49 KB
/
client_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mkarim <mkarim@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/17 14:59:50 by mkarim #+# #+# */
/* Updated: 2022/02/09 11:14:31 by mkarim ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void ft_send(int pid, char c)
{
int i;
i = 7;
while (i >= 0)
{
if ((c >> i) & 1)
kill(pid, SIGUSR1);
else
kill(pid, SIGUSR2);
i--;
usleep(800);
}
}
void client_handler(int s)
{
if (s == SIGUSR1)
ft_putstr("L'msg wsal\n");
}
int main(int argc, char **argv)
{
int pid;
int i;
struct sigaction s;
s.__sigaction_u.__sa_handler = &client_handler;
sigaction(SIGUSR1, &s, NULL);
i = 0;
if (argc == 3)
{
pid = ft_atoi(argv[1]);
while (argv[2][i])
{
ft_send(pid, argv[2][i]);
i++;
}
ft_send(pid, argv[2][i]);
}
else
ft_putstr("Bghina 3 arguments assat\n");
}