la communication fonctionne avec signal

This commit is contained in:
hugogogo
2021-08-29 16:45:21 +02:00
parent ce1e7d46c5
commit a5f922ed6e
7 changed files with 31 additions and 42 deletions
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+1 -27
View File
@@ -1,5 +1,4 @@
#include "../includes/minitalk.h" #include "../includes/minitalk.h"
#include <stdlib.h> //for atoi
int usage(void) int usage(void)
{ {
@@ -18,9 +17,8 @@ void send_char(int server_pid, char c)
if ((c & mask) == 0) if ((c & mask) == 0)
kill(server_pid, SIGUSR2); kill(server_pid, SIGUSR2);
mask >>= 1; mask >>= 1;
usleep(300); usleep(20);
} }
} }
void send_message(int server_pid, char *msg) void send_message(int server_pid, char *msg)
@@ -31,30 +29,6 @@ void send_message(int server_pid, char *msg)
msg++; msg++;
} }
send_char(server_pid, *msg); send_char(server_pid, *msg);
// if (!ft_strcmp(msg, "SIGUSR1"))
// kill(server_pid, SIGUSR1);
// if (!ft_strcmp(msg, "SIGUSR2"))
// kill(server_pid, SIGUSR2);
// int mask;
// mask = 1 << 6;
// char character;
// character = 'c';
// ft_printf("%c %i\n", character, character, mask);
// while (mask != 0)
// {
// ft_putchar('\n');
// ft_putnbrbase(character, "01");
// ft_putchar('\n');
// ft_putnbrbase(mask, "01");
// ft_putchar('\n');
// if ((character & mask) != 0)
// ft_putchar('1');
// if ((character & mask) == 0)
// ft_putchar('0');
// mask >>= 1;
// }
} }
int main(int ac, char **av) int main(int ac, char **av)
+26 -15
View File
@@ -20,6 +20,22 @@ void init_message(void)
message.text = ft_strdup(""); message.text = ft_strdup("");
} }
void concat_msg()
{
if (message.count_bits == 7)
{
if (message.character == 0)
{
ft_printf("%s\n", message.text);
message.text = ft_strdup("");
}
else
message.text = ft_strjoinfree(message.text, ft_strdup(&(message.character)));
message.count_bits = 0;
message.character = 0;
}
}
int main() int main()
{ {
signal(SIGUSR1, sig_handler_1); signal(SIGUSR1, sig_handler_1);
@@ -27,25 +43,11 @@ int main()
ft_putnbrendl((int)getpid()); ft_putnbrendl((int)getpid());
init_message(); init_message();
while (1) while (1)
{ concat_msg();
if (message.count_bits == 7)
{
if (message.character == 0)
{
ft_printf("%s\n", message.text);
message.text = ft_strdup("");
}
else
message.text = ft_strjoinfree(message.text, ft_strdup(&(message.character)));
message.count_bits = 0;
message.character = 0;
}
}
return (0); return (0);
} }
/* /*
**
** allowed functions : ** allowed functions :
** - write ** - write
** - signal ** - signal
@@ -61,6 +63,15 @@ int main()
** - usleep ** - usleep
** - exit ** - exit
** **
**
** cmm
** deii
** enlc
** ctlr
** iiio
** 0.0010
** 10
**
** you can only use two signals : ** you can only use two signals :
** - SIGUSR1 ** - SIGUSR1
** - SIGUSR2 ** - SIGUSR2
+4
View File
@@ -4,3 +4,7 @@ cnealin azelj aze .
cnealin azelj aze . cnealin azelj aze .
cnealin azelj aze cnealin azelj aze
cnealin azelj aze..... cnealin azelj aze.....
21377
cnealin azelj aze.....
cnealin azelj aze
salut heuuu