-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
75 lines (67 loc) · 1.71 KB
/
client.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: joramire <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/22 12:05:05 by joramire #+# #+# */
/* Updated: 2023/01/28 19:35:10 by joramire ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <signal.h>
#include "Printf/ft_printf.h"
int g_pass = 0;
void sig_handler(int sigtype)
{
int aux;
aux = sigtype;
g_pass = 1;
}
void ft_send_bytes(int c, int server_pid)
{
int bit;
bit = 0;
while (bit < 8)
{
g_pass = 0;
if ((c & (1 << bit)) != 0)
{
kill(server_pid, SIGUSR1);
}
else
{
kill(server_pid, SIGUSR2);
}
bit++;
while (g_pass == 0)
{
usleep(1);
}
}
}
int main(int argc, char **argv)
{
struct sigaction signals;
int i;
if (argc != 3)
{
ft_printf("Error: number of arguments incorrect\n");
return (1);
}
else
{
signals.sa_handler = sig_handler;
sigemptyset(&signals.sa_mask);
signals.sa_flags = 0;
sigaction(SIGUSR1, &signals, NULL);
i = 0;
while (argv[1][i] != '\0')
{
ft_send_bytes(argv[1][i], ft_atoi(argv[2]));
i++;
}
}
return (0);
}