-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
67 lines (60 loc) · 1.64 KB
/
Copy pathclient.c
File metadata and controls
67 lines (60 loc) · 1.64 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
58
59
60
61
62
63
64
65
66
67
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cliente_teste.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: smagalha <smagalha@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/08 22:24:19 by smagalha #+# #+# */
/* Updated: 2023/04/08 22:44:35 by smagalha ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
static void send_bits(int pid, char *str);
static void handle_signal(int sig);
int main(int argc, char **argv)
{
if (argc != 3)
{
ft_putstr_fd("Wrong number of arguments!\n", 1);
return (1);
}
signal(SIGUSR1, handle_signal);
signal(SIGUSR2, handle_signal);
send_bits(ft_atoi(argv[1]), argv[2]);
while (1)
pause();
return (0);
}
static void send_bits(int pid, char *str)
{
int i;
char c;
while (*str)
{
i = 8;
c = *str++;
while (i--)
{
if (c >> i & 1)
kill(pid, SIGUSR2);
else
kill(pid, SIGUSR1);
usleep(200);
}
}
i = 8;
while (i--)
{
kill(pid, SIGUSR1);
usleep(100);
}
}
static void handle_signal(int sig)
{
if (sig == SIGUSR2)
{
ft_putstr_fd("Message was received by the server\n", 1);
exit(0);
}
}