norm ok fonctionnement ok leaks ok
This commit is contained in:
9
Makefile
9
Makefile
@@ -28,16 +28,14 @@ C_DEPS = ./includes/client.h
|
||||
# rules to execute # recipe | $< : 1st prerequisite
|
||||
# - - - - - - - - - - - - - - # recipe | $^ : all prerequisites
|
||||
|
||||
all: libft $(S_NAME) $(C_NAME)
|
||||
|
||||
libft:
|
||||
@echo "hello"
|
||||
make -C $(LDIR)
|
||||
all: $(S_NAME) $(C_NAME)
|
||||
|
||||
$(S_NAME): $(S_OBJS) $(S_DEPS)
|
||||
make -C $(LDIR)
|
||||
$(CC) $(CFLAGS) -o $@ $< $(LFLAGS)
|
||||
|
||||
$(C_NAME): $(C_OBJS) $(C_DEPS)
|
||||
make -C $(LDIR)
|
||||
$(CC) $(CFLAGS) -o $@ $< $(LFLAGS)
|
||||
|
||||
$(ODIR)/%.o: %.c | $(ODIR)
|
||||
@@ -55,6 +53,7 @@ clean:
|
||||
/bin/rm -f $(S_OBJS) $(C_OBJS)
|
||||
|
||||
fclean: clean
|
||||
make fclean -C $(LDIR)
|
||||
/bin/rm -rf $(ODIR)
|
||||
/bin/rm -f $(S_NAME) $(C_NAME)
|
||||
/bin/rm -rf a.out a.out.dSYM
|
||||
|
||||
BIN
builds/client.o
BIN
builds/client.o
Binary file not shown.
BIN
builds/server.o
BIN
builds/server.o
Binary file not shown.
@@ -15,7 +15,7 @@ typedef struct s_client
|
||||
int done;
|
||||
} t_client;
|
||||
|
||||
t_client client;
|
||||
t_client g_client;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
# include <unistd.h> // for getpid
|
||||
# include "libft.h"
|
||||
|
||||
typedef struct s_message
|
||||
typedef struct s_server
|
||||
{
|
||||
unsigned int count_bits;
|
||||
char character;
|
||||
char *text;
|
||||
} t_message;
|
||||
} t_server;
|
||||
|
||||
t_message message;
|
||||
t_server g_server;
|
||||
|
||||
#endif
|
||||
|
||||
1
libft
Submodule
1
libft
Submodule
Submodule libft added at c335eb1f6a
@@ -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