-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_bit_by_bit.c
More file actions
62 lines (57 loc) · 1.67 KB
/
ft_bit_by_bit.c
File metadata and controls
62 lines (57 loc) · 1.67 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bit_by_bit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: davdiaz- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/27 16:17:47 by davdiaz- #+# #+# */
/* Updated: 2025/05/27 16:22:23 by davdiaz- ### ########.fr */
/* */
/* ************************************************************************** */
#include "client.h"
static void ft_eot(void)
{
char bit;
if (g_client.eot == 0)
{
g_client.eot = 1;
g_client.j = 0;
ft_strbinary(0x04, g_client.buffer);
}
if (g_client.j < 8)
{
bit = g_client.buffer[g_client.j];
if (bit == '1')
kill(g_client.pid, SIGUSR1);
else
kill(g_client.pid, SIGUSR2);
if (g_client.j == 7)
g_client.end = 1;
g_client.j++;
}
}
void ft_bit_by_bit(void)
{
char bit;
if (g_client.end == 1)
return ;
if (g_client.j >= 8)
{
g_client.j = 0;
g_client.index++;
}
if (g_client.str[g_client.index] != '\0')
{
if (g_client.j == 0)
ft_strbinary(g_client.str[g_client.index], g_client.buffer);
bit = g_client.buffer[g_client.j];
if (bit == '1')
kill(g_client.pid, SIGUSR1);
else
kill(g_client.pid, SIGUSR2);
g_client.j++;
}
else
ft_eot();
}