-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
75 lines (68 loc) · 1.81 KB
/
client.c
File metadata and controls
75 lines (68 loc) · 1.81 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
68
69
70
71
72
73
74
75
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: slepetit <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/12 16:45:03 by slepetit #+# #+# */
/* Updated: 2022/10/19 18:08:34 by slepetit ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
char *g_str;
void ft_send(int sig, siginfo_t *info, void *ignore)
{
static int i;
static int bit;
(void)sig;
(void)ignore;
if (g_str[i])
{
if (g_str[i] >> bit & 1)
kill(info->si_pid, SIGUSR1);
else
kill(info->si_pid, SIGUSR2);
bit++;
if (bit == 8)
{
bit = 0;
i++;
}
}
else if (g_str[i] == '\0')
{
kill(info->si_pid, SIGUSR2);
bit ++;
if (bit == 8)
exit(EXIT_SUCCESS);
}
}
void ft_handler_client(void)
{
sigset_t signal;
struct sigaction action;
sigemptyset(&signal);
sigaddset(&signal, SIGUSR1);
action.sa_flags = SA_SIGINFO;
action.sa_sigaction = &ft_send;
sigaction(SIGUSR1, &action, NULL);
while (1)
pause();
}
int main(int ac, char **av)
{
g_str = av[2];
if (ac != 3)
{
ft_putstr("Error with arguments\n");
exit(EXIT_FAILURE);
}
if (kill(ft_atoi(av[1]), SIGUSR1) < 0)
{
ft_putstr("Error PID\n");
exit(EXIT_FAILURE);
}
ft_handler_client();
return (0);
}