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
|
# rules to execute # recipe | $< : 1st prerequisite
|
||||||
# - - - - - - - - - - - - - - # recipe | $^ : all prerequisites
|
# - - - - - - - - - - - - - - # recipe | $^ : all prerequisites
|
||||||
|
|
||||||
all: libft $(S_NAME) $(C_NAME)
|
all: $(S_NAME) $(C_NAME)
|
||||||
|
|
||||||
libft:
|
|
||||||
@echo "hello"
|
|
||||||
make -C $(LDIR)
|
|
||||||
|
|
||||||
$(S_NAME): $(S_OBJS) $(S_DEPS)
|
$(S_NAME): $(S_OBJS) $(S_DEPS)
|
||||||
|
make -C $(LDIR)
|
||||||
$(CC) $(CFLAGS) -o $@ $< $(LFLAGS)
|
$(CC) $(CFLAGS) -o $@ $< $(LFLAGS)
|
||||||
|
|
||||||
$(C_NAME): $(C_OBJS) $(C_DEPS)
|
$(C_NAME): $(C_OBJS) $(C_DEPS)
|
||||||
|
make -C $(LDIR)
|
||||||
$(CC) $(CFLAGS) -o $@ $< $(LFLAGS)
|
$(CC) $(CFLAGS) -o $@ $< $(LFLAGS)
|
||||||
|
|
||||||
$(ODIR)/%.o: %.c | $(ODIR)
|
$(ODIR)/%.o: %.c | $(ODIR)
|
||||||
@@ -55,6 +53,7 @@ clean:
|
|||||||
/bin/rm -f $(S_OBJS) $(C_OBJS)
|
/bin/rm -f $(S_OBJS) $(C_OBJS)
|
||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
|
make fclean -C $(LDIR)
|
||||||
/bin/rm -rf $(ODIR)
|
/bin/rm -rf $(ODIR)
|
||||||
/bin/rm -f $(S_NAME) $(C_NAME)
|
/bin/rm -f $(S_NAME) $(C_NAME)
|
||||||
/bin/rm -rf a.out a.out.dSYM
|
/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;
|
int done;
|
||||||
} t_client;
|
} t_client;
|
||||||
|
|
||||||
t_client client;
|
t_client g_client;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,12 @@
|
|||||||
# include <unistd.h> // for getpid
|
# include <unistd.h> // for getpid
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
|
|
||||||
typedef struct s_message
|
typedef struct s_server
|
||||||
{
|
{
|
||||||
unsigned int count_bits;
|
unsigned int count_bits;
|
||||||
char character;
|
char character;
|
||||||
char *text;
|
} t_server;
|
||||||
} t_message;
|
|
||||||
|
|
||||||
t_message message;
|
t_server g_server;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
1
libft
Submodule
1
libft
Submodule
Submodule libft added at c335eb1f6a
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
int usage(void)
|
int usage(void)
|
||||||
{
|
{
|
||||||
ft_printf("usage: ./client [server pid] [message]\n");
|
ft_putstr("usage: ./client [server pid] [message]\n");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,25 +17,25 @@ void send_char(char c, int mask, int server_pid)
|
|||||||
void send_message(int sig_num)
|
void send_message(int sig_num)
|
||||||
{
|
{
|
||||||
(void)sig_num;
|
(void)sig_num;
|
||||||
client.mask >>= 1;
|
g_client.mask >>= 1;
|
||||||
if (client.mask == 0)
|
if (g_client.mask == 0)
|
||||||
{
|
{
|
||||||
client.mask = 1 << 6;
|
g_client.mask = 1 << 6;
|
||||||
if (client.text[client.count_char] == '\0')
|
if (g_client.text[g_client.count_char] == '\0')
|
||||||
client.done = 1;
|
g_client.done = 1;
|
||||||
(client.count_char)++;
|
(g_client.count_char)++;
|
||||||
}
|
}
|
||||||
if (client.done == 0)
|
if (g_client.done == 0)
|
||||||
send_char(client.text[client.count_char], client.mask, client.srv_pid);
|
send_char(g_client.text[g_client.count_char], g_client.mask, g_client.srv_pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_client(int pid, char *msg)
|
void init_client(int pid, char *msg)
|
||||||
{
|
{
|
||||||
client.mask = 1 << 7;
|
g_client.mask = 1 << 7;
|
||||||
client.count_char = 0;
|
g_client.count_char = 0;
|
||||||
client.srv_pid = pid;
|
g_client.srv_pid = pid;
|
||||||
client.text = msg;
|
g_client.text = msg;
|
||||||
client.done = 0;
|
g_client.done = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
@@ -45,7 +45,7 @@ int main(int ac, char **av)
|
|||||||
return (usage());
|
return (usage());
|
||||||
init_client(ft_atoi(av[1]), av[2]);
|
init_client(ft_atoi(av[1]), av[2]);
|
||||||
kill((int)getpid(), SIGUSR1);
|
kill((int)getpid(), SIGUSR1);
|
||||||
while (client.done == 0)
|
while (g_client.done == 0)
|
||||||
;
|
;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
void send_char(void)
|
void send_char(void)
|
||||||
{
|
{
|
||||||
if (message.count_bits == 7)
|
if (g_server.count_bits == 7)
|
||||||
{
|
{
|
||||||
ft_putchar(message.character);
|
ft_putchar(g_server.character);
|
||||||
message.count_bits = 0;
|
g_server.count_bits = 0;
|
||||||
message.character = 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)sig_num;
|
||||||
(void)context;
|
(void)context;
|
||||||
message.character ^= 1 << (6 - message.count_bits);
|
g_server.character ^= 1 << (6 - g_server.count_bits);
|
||||||
message.count_bits++;
|
g_server.count_bits++;
|
||||||
send_char();
|
send_char();
|
||||||
kill(info->si_pid, SIGUSR1);
|
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)sig_num;
|
||||||
(void)context;
|
(void)context;
|
||||||
message.count_bits++;
|
g_server.count_bits++;
|
||||||
send_char();
|
send_char();
|
||||||
kill(info->si_pid, SIGUSR1);
|
kill(info->si_pid, SIGUSR1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_message(void)
|
void init_message(void)
|
||||||
{
|
{
|
||||||
message.count_bits = 0;
|
g_server.count_bits = 0;
|
||||||
message.character = 0;
|
g_server.character = 0;
|
||||||
message.text = ft_strdup("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
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
|
** UNITS PREFIX
|
||||||
**
|
**
|
||||||
** times in seconds, deci, centi, milli, micros and nano :
|
** times in seconds, deci, centi, milli, micros and nano :
|
||||||
|
|||||||
Reference in New Issue
Block a user