norm ok fonctionnement ok leaks ok
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
int usage(void)
|
||||
{
|
||||
ft_printf("usage: ./client [server pid] [message]\n");
|
||||
ft_putstr("usage: ./client [server pid] [message]\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -17,25 +17,25 @@ void send_char(char c, int mask, int server_pid)
|
||||
void send_message(int sig_num)
|
||||
{
|
||||
(void)sig_num;
|
||||
client.mask >>= 1;
|
||||
if (client.mask == 0)
|
||||
g_client.mask >>= 1;
|
||||
if (g_client.mask == 0)
|
||||
{
|
||||
client.mask = 1 << 6;
|
||||
if (client.text[client.count_char] == '\0')
|
||||
client.done = 1;
|
||||
(client.count_char)++;
|
||||
g_client.mask = 1 << 6;
|
||||
if (g_client.text[g_client.count_char] == '\0')
|
||||
g_client.done = 1;
|
||||
(g_client.count_char)++;
|
||||
}
|
||||
if (client.done == 0)
|
||||
send_char(client.text[client.count_char], client.mask, client.srv_pid);
|
||||
if (g_client.done == 0)
|
||||
send_char(g_client.text[g_client.count_char], g_client.mask, g_client.srv_pid);
|
||||
}
|
||||
|
||||
void init_client(int pid, char *msg)
|
||||
{
|
||||
client.mask = 1 << 7;
|
||||
client.count_char = 0;
|
||||
client.srv_pid = pid;
|
||||
client.text = msg;
|
||||
client.done = 0;
|
||||
g_client.mask = 1 << 7;
|
||||
g_client.count_char = 0;
|
||||
g_client.srv_pid = pid;
|
||||
g_client.text = msg;
|
||||
g_client.done = 0;
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
@@ -45,7 +45,7 @@ int main(int ac, char **av)
|
||||
return (usage());
|
||||
init_client(ft_atoi(av[1]), av[2]);
|
||||
kill((int)getpid(), SIGUSR1);
|
||||
while (client.done == 0)
|
||||
while (g_client.done == 0)
|
||||
;
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
void send_char(void)
|
||||
{
|
||||
if (message.count_bits == 7)
|
||||
if (g_server.count_bits == 7)
|
||||
{
|
||||
ft_putchar(message.character);
|
||||
message.count_bits = 0;
|
||||
message.character = 0;
|
||||
ft_putchar(g_server.character);
|
||||
g_server.count_bits = 0;
|
||||
g_server.character = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ void sig_handler_1(int sig_num, siginfo_t *info, void *context)
|
||||
{
|
||||
(void)sig_num;
|
||||
(void)context;
|
||||
message.character ^= 1 << (6 - message.count_bits);
|
||||
message.count_bits++;
|
||||
g_server.character ^= 1 << (6 - g_server.count_bits);
|
||||
g_server.count_bits++;
|
||||
send_char();
|
||||
kill(info->si_pid, SIGUSR1);
|
||||
}
|
||||
@@ -24,16 +24,15 @@ void sig_handler_2(int sig_num, siginfo_t *info, void *context)
|
||||
{
|
||||
(void)sig_num;
|
||||
(void)context;
|
||||
message.count_bits++;
|
||||
g_server.count_bits++;
|
||||
send_char();
|
||||
kill(info->si_pid, SIGUSR1);
|
||||
}
|
||||
|
||||
void init_message(void)
|
||||
{
|
||||
message.count_bits = 0;
|
||||
message.character = 0;
|
||||
message.text = ft_strdup("");
|
||||
g_server.count_bits = 0;
|
||||
g_server.character = 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@@ -79,15 +78,6 @@ int main(void)
|
||||
**
|
||||
**
|
||||
** # # # # # # # # # # # # # # # # # # # #
|
||||
** ressources
|
||||
**
|
||||
** use of getpid : https://www.includehelp.com/c/getpid-and-getppid-functions-in-c-linux.aspx
|
||||
** use of signal : https://linuxhint.com/signal_handlers_c_programming_language
|
||||
** use of sigaction : https://stackoverflow.com/a/17572787/9497573
|
||||
** standard signal vs real time signals (with queue option) : https://www.softprayog.in/programming/posix-real-time-signals-in-linux
|
||||
**
|
||||
**
|
||||
** # # # # # # # # # # # # # # # # # # # #
|
||||
** UNITS PREFIX
|
||||
**
|
||||
** times in seconds, deci, centi, milli, micros and nano :
|
||||
|
||||
Reference in New Issue
Block a user