implementation recepetion message incomplete et makefile foncitonne avec deux headers separes
This commit is contained in:
39
Makefile
39
Makefile
@@ -3,46 +3,41 @@
|
|||||||
# variables names # value
|
# variables names # value
|
||||||
# - - - - - - - - - - - - - - # ! name is case sensitive
|
# - - - - - - - - - - - - - - # ! name is case sensitive
|
||||||
|
|
||||||
SERVER = server
|
|
||||||
CLIENT = client
|
|
||||||
CC = gcc
|
|
||||||
VPATH = srcs
|
VPATH = srcs
|
||||||
|
CC = gcc
|
||||||
S_SRCS = server.c
|
|
||||||
C_SRCS = client.c
|
|
||||||
|
|
||||||
ODIR = ./builds
|
ODIR = ./builds
|
||||||
S_OBJS = $(S_SRCS:%.c=$(ODIR)/%.o)
|
IDIR = ./includes ./libft/includes
|
||||||
C_OBJS = $(C_SRCS:%.c=$(ODIR)/%.o)
|
|
||||||
|
|
||||||
DEPS = ./includes/minitalk.h \
|
|
||||||
./libft/includes/libft.h
|
|
||||||
IDIR = $(dir $(DEPS))
|
|
||||||
# $(dir PATH/TO/FILE) expands to "PATH/TO/" -> the directory of a file
|
|
||||||
|
|
||||||
LDIR = ./libft
|
LDIR = ./libft
|
||||||
_LIBS = libft.a
|
LIBS = ft
|
||||||
LIBS = $(_LIBS:lib%.a=%)
|
|
||||||
|
|
||||||
CFLAGS = $(IDIR:%=-I%)
|
CFLAGS = $(IDIR:%=-I%)
|
||||||
CFLAGS += -g3 -Wall -Wextra -Werror
|
CFLAGS += -g3 -Wall -Wextra -Werror
|
||||||
LFLAGS = -L./libft -lft
|
LFLAGS = -L./libft -lft
|
||||||
|
|
||||||
|
S_NAME = server
|
||||||
|
S_SRCS = server.c
|
||||||
|
S_OBJS = $(S_SRCS:%.c=$(ODIR)/%.o)
|
||||||
|
S_DEPS = ./includes/server.h
|
||||||
|
|
||||||
|
C_NAME = client
|
||||||
|
C_SRCS = client.c
|
||||||
|
C_OBJS = $(C_SRCS:%.c=$(ODIR)/%.o)
|
||||||
|
C_DEPS = ./includes/client.h
|
||||||
|
|
||||||
|
|
||||||
# - - - - - - - - - - - - - - # target: prerequisites | $@ : target
|
# - - - - - - - - - - - - - - # target: prerequisites | $@ : target
|
||||||
# rules to execute # recipe | $< : 1st prerequisite
|
# rules to execute # recipe | $< : 1st prerequisite
|
||||||
# - - - - - - - - - - - - - - # recipe | $^ : all prerequisites
|
# - - - - - - - - - - - - - - # recipe | $^ : all prerequisites
|
||||||
|
|
||||||
all: libft $(SERVER) $(CLIENT)
|
all: libft $(S_NAME) $(C_NAME)
|
||||||
|
|
||||||
libft:
|
libft:
|
||||||
@echo "hello"
|
@echo "hello"
|
||||||
make -C $(LDIR)
|
make -C $(LDIR)
|
||||||
|
|
||||||
$(SERVER): $(S_OBJS) $(DEPS)
|
$(S_NAME): $(S_OBJS) $(S_DEPS)
|
||||||
$(CC) $(CFLAGS) -o $@ $< $(LFLAGS)
|
$(CC) $(CFLAGS) -o $@ $< $(LFLAGS)
|
||||||
|
|
||||||
$(CLIENT): $(C_OBJS) $(DEPS)
|
$(C_NAME): $(C_OBJS) $(C_DEPS)
|
||||||
$(CC) $(CFLAGS) -o $@ $< $(LFLAGS)
|
$(CC) $(CFLAGS) -o $@ $< $(LFLAGS)
|
||||||
|
|
||||||
$(ODIR)/%.o: %.c | $(ODIR)
|
$(ODIR)/%.o: %.c | $(ODIR)
|
||||||
@@ -61,7 +56,7 @@ clean:
|
|||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
/bin/rm -rf $(ODIR)
|
/bin/rm -rf $(ODIR)
|
||||||
/bin/rm -f $(SERVER) $(CLIENT)
|
/bin/rm -f $(S_NAME) $(C_NAME)
|
||||||
/bin/rm -rf a.out a.out.dSYM
|
/bin/rm -rf a.out a.out.dSYM
|
||||||
|
|
||||||
libfclean:
|
libfclean:
|
||||||
|
|||||||
BIN
builds/client.o
Normal file
BIN
builds/client.o
Normal file
Binary file not shown.
BIN
builds/server.o
Normal file
BIN
builds/server.o
Normal file
Binary file not shown.
12
includes/client.h
Normal file
12
includes/client.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef CLIENT_H
|
||||||
|
# define CLIENT_H
|
||||||
|
|
||||||
|
# include <signal.h> // for signal kill sigaction
|
||||||
|
# include <sys/types.h> // for getpid kill
|
||||||
|
# include <unistd.h> // for getpid
|
||||||
|
# include "libft.h"
|
||||||
|
|
||||||
|
int msg_received;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef MINITALK_H
|
#ifndef SERVER_H
|
||||||
# define MINITALK_H
|
# define SERVER_H
|
||||||
|
|
||||||
# include <signal.h> // for signal kill sigaction
|
# include <signal.h> // for signal kill sigaction
|
||||||
# include <sys/types.h> // for getpid kill
|
# include <sys/types.h> // for getpid kill
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "../includes/minitalk.h"
|
#include "client.h"
|
||||||
|
|
||||||
int usage(void)
|
int usage(void)
|
||||||
{
|
{
|
||||||
@@ -13,12 +13,15 @@ void send_char(int server_pid, char c)
|
|||||||
mask = 1 << 6;
|
mask = 1 << 6;
|
||||||
while (mask != 0)
|
while (mask != 0)
|
||||||
{
|
{
|
||||||
if ((c & mask) != 0)
|
if (msg_received == 1)
|
||||||
kill(server_pid, SIGUSR1);
|
{
|
||||||
if ((c & mask) == 0)
|
if ((c & mask) != 0)
|
||||||
kill(server_pid, SIGUSR2);
|
kill(server_pid, SIGUSR1);
|
||||||
mask >>= 1;
|
if ((c & mask) == 0)
|
||||||
usleep(1);
|
kill(server_pid, SIGUSR2);
|
||||||
|
msg_received = 0;
|
||||||
|
mask >>= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,11 +35,19 @@ void send_message(int server_pid, char *msg)
|
|||||||
send_char(server_pid, *msg);
|
send_char(server_pid, *msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void message_received(int sig_num)
|
||||||
|
{
|
||||||
|
(void)sig_num;
|
||||||
|
msg_received = 1;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
|
signal(SIGUSR1, message_received);
|
||||||
if (ac != 3)
|
if (ac != 3)
|
||||||
return (usage());
|
return (usage());
|
||||||
send_message(ft_atoi(av[1]), av[2]);
|
msg_received = 1;
|
||||||
ft_putnbrendl((int)getpid());
|
ft_putnbrendl((int)getpid());
|
||||||
|
send_message(ft_atoi(av[1]), av[2]);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "minitalk.h"
|
#include "server.h"
|
||||||
|
|
||||||
void sig_handler_1(int sig_num, siginfo_t *info, void *context)
|
void sig_handler_1(int sig_num, siginfo_t *info, void *context)
|
||||||
{
|
{
|
||||||
(void)sig_num;
|
(void)sig_num;
|
||||||
(void)context;
|
(void)context;
|
||||||
kill(info->sa__pid, SIGUSR1);
|
kill(info->si_pid, SIGUSR1);
|
||||||
message.character ^= 1 << (6 - message.count_bits);
|
message.character ^= 1 << (6 - message.count_bits);
|
||||||
message.count_bits++;
|
message.count_bits++;
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,20 @@ void sig_handler_2(int sig_num, siginfo_t *info, void *context)
|
|||||||
{
|
{
|
||||||
(void)sig_num;
|
(void)sig_num;
|
||||||
(void)context;
|
(void)context;
|
||||||
kill(info->sa__pid, SIGUSR2);
|
kill(info->si_pid, SIGUSR1);
|
||||||
|
message.count_bits++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handler_1(int sig_num)
|
||||||
|
{
|
||||||
|
(void)sig_num;
|
||||||
|
message.character ^= 1 << (6 - message.count_bits);
|
||||||
|
message.count_bits++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handler_2(int sig_num)
|
||||||
|
{
|
||||||
|
(void)sig_num;
|
||||||
message.count_bits++;
|
message.count_bits++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +64,10 @@ int main()
|
|||||||
act_2.sa_sigaction = sig_handler_2;
|
act_2.sa_sigaction = sig_handler_2;
|
||||||
sigaction(SIGUSR1, &act_1, NULL);
|
sigaction(SIGUSR1, &act_1, NULL);
|
||||||
sigaction(SIGUSR2, &act_2, NULL);
|
sigaction(SIGUSR2, &act_2, NULL);
|
||||||
|
|
||||||
|
// signal(SIGUSR1, handler_1);
|
||||||
|
// signal(SIGUSR2, handler_2);
|
||||||
|
|
||||||
ft_putnbrendl((int)getpid());
|
ft_putnbrendl((int)getpid());
|
||||||
init_message();
|
init_message();
|
||||||
while (1)
|
while (1)
|
||||||
|
|||||||
Reference in New Issue
Block a user