message echange ok mais pas eol

This commit is contained in:
hugogogo
2021-08-29 13:20:34 +02:00
parent cab9adafda
commit bb232a52a1
7 changed files with 34 additions and 32 deletions

Binary file not shown.

Binary file not shown.

BIN
client

Binary file not shown.

View File

@@ -1,9 +1,18 @@
#ifndef MINITALK_H #ifndef MINITALK_H
# define MINITALK_H # define MINITALK_H
# include <signal.h> // for signal kill # include <signal.h> // for signal kill sigaction
# include <sys/types.h> // for getpid kill # include <sys/types.h> // for getpid kill
# include <unistd.h> // for getpid # include <unistd.h> // for getpid
# include "libft.h" # include "libft.h"
typedef struct s_message
{
unsigned int count_bits;
char character;
char *text;
} t_message;
t_message message;
#endif #endif

BIN
server

Binary file not shown.

View File

@@ -26,8 +26,8 @@ void send_char(int server_pid, char c)
ft_putnbr(0); ft_putnbr(0);
kill(server_pid, SIGUSR2); kill(server_pid, SIGUSR2);
} }
sleep(1);
mask >>= 1; mask >>= 1;
usleep(300);
} }
} }

View File

@@ -1,49 +1,42 @@
#include "minitalk.h" #include "minitalk.h"
#include <stdio.h> // for printf
//int ft_printf(char *string, ...);
void sig_handler_1(int sig_num) void sig_handler_1(int sig_num)
{ {
(void)sig_num; (void)sig_num;
ft_putnbr(1); message.character ^= 1 << (6 - message.count_bits);
message.count_bits++;
} }
void sig_handler_2(int sig_num) void sig_handler_2(int sig_num)
{ {
(void)sig_num; (void)sig_num;
ft_putnbr(0); message.count_bits++;
}
void init_message(void)
{
message.count_bits = 0;
message.character = 0;
message.text = ft_strdup("");
} }
int main() int main()
{ {
int pid;
pid = (int)getpid();
ft_printf("%i\n", pid);
signal(SIGUSR1, sig_handler_1); signal(SIGUSR1, sig_handler_1);
signal(SIGUSR2, sig_handler_2); signal(SIGUSR2, sig_handler_2);
ft_putnbrendl((int)getpid());
// int mask; init_message();
// mask = 1 << 6; while (1)
// char character; {
// character = 'c'; if (message.count_bits == 7)
// ft_printf("%c %i\n", character, character, mask); {
// while (mask != 0) message.text = ft_strjoinfree(message.text, ft_strdup(&(message.character)));
// { ft_putnbrbase(message.character, "01");
// ft_putchar('\n'); ft_printf(" %c %s\n", message.character, message.text);
// ft_putnbrbase(character, "01"); message.count_bits = 0;
// ft_putchar('\n'); message.character = 0;
// ft_putnbrbase(mask, "01"); }
// ft_putchar('\n'); }
// if ((character & mask) != 0)
// ft_putchar('1');
// if ((character & mask) == 0)
// ft_putchar('0');
// mask >>= 1;
// }
while (1);
return (0); return (0);
} }