Skip to content

Commit 914b75f

Browse files
Merge pull request #2 from hardyrafael17/1-add-modulation-converting-sets-of-bits
1 add modulation converting sets of bits
2 parents 55e1add + e072899 commit 914b75f

File tree

10 files changed

+244
-198
lines changed

10 files changed

+244
-198
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ tserver
33
.gitignore
44
a.out
55
minitalk.a
6-
server2.o
6+
tserver.o
7+
tclient.o

Makefile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ CFLAGS = -Wall -Werror -Wextra
1414

1515
XFLAGS = -o
1616

17-
RUN_FLAGS = "Hola mundo Hola mundo ola mundo HHola mundo Hola mundo ola mundo ola mundo Hola mundo ola mundo"
18-
1917
all : $(NAME)
2018

2119
$(NAME) : $(OBJS)
22-
$(AR) $(NAME) $(OBJS)
20+
@$(AR) $(NAME) $(OBJS)
2321

2422
%.o: %.c
25-
$(CC) $(CFLAGS) -c $< -o $@
23+
@$(CC) $(CFLAGS) -c $< -o $@
2624

2725
clean:
28-
$(RM) ${OBJS}
26+
@$(RM) ${OBJS}
2927

3028
fclean: clean
31-
$(RM) $(NAME)
29+
@$(RM) $(NAME)
3230

3331
re: fclean all
3432

3533
#personal rules
3634

37-
excecutable: all
38-
$(CC) client.o $(XFLAGS) tclient && $(CC) server2.o $(XFLAGS) tserver
35+
client:
36+
gcc client.c -o tclient.o
37+
38+
server:
39+
gcc server.c -o tserver.o
3940

40-
vim:
41-
gcc client.c -o tclient && gcc server2.c -o tserver && echo "compliation completed"
41+
k: fclean client server
4242

4343
.PHONY: all clean fclean re bonus

client.c

Lines changed: 73 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,92 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* client.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: hardy <hardy@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/04/20 19:17:39 by hardy #+# #+# */
9+
/* Updated: 2022/04/20 19:43:25 by hardy ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
113
#include "minitalk.h"
214

3-
static status_t operation;
15+
static t_data g_operation;
416

5-
void
6-
resume(int signo, siginfo_t *info, void *context)
17+
int
18+
send_singal(int type)
719
{
8-
if(!operation.context)
20+
int lock;
21+
22+
lock = 1;
23+
if (type && lock)
24+
{
25+
while (type && lock)
926
{
10-
operation.context = context;
11-
operation.client_pid = info->si_pid;
12-
operation.client_pid = signo;
13-
}
14-
return;
27+
if (!kill(g_operation.server_pid, SIGUSR2))
28+
{
29+
lock = 0;
30+
}
31+
}
32+
}
33+
else
34+
{
35+
while (lock)
36+
{
37+
if (!kill(g_operation.server_pid, SIGUSR1))
38+
{
39+
lock = 0;
40+
}
41+
}
42+
}
43+
return (1);
1544
}
1645

1746
void
18-
send_char(char *string, int message_length)
47+
resume(int signo, siginfo_t *info, void *context)
1948
{
20-
int j;
21-
int i;
49+
if (!g_operation.context)
50+
{
51+
g_operation.context = context;
52+
g_operation.client_pid = info->si_pid;
53+
g_operation.client_pid = signo;
54+
}
55+
return ;
56+
}
2257

23-
j = 0;
24-
while(string && string[j++])
58+
void
59+
send_char(char *string, int message_length)
60+
{
61+
while (string && string[g_operation.counter])
2562
{
26-
printf("Sending byte\n");
27-
i = 8;
28-
while (i--)
63+
g_operation.shift_count = 8;
64+
while (g_operation.shift_count--)
2965
{
30-
if (string[j] >> i && 1)
31-
kill(operation.server_pid, SIGUSR2);
66+
if (string[g_operation.counter] >> g_operation.shift_count & 1)
67+
send_singal(1);
3268
else
33-
kill(operation.server_pid, SIGUSR1);
69+
send_singal(0);
3470
pause();
3571
}
36-
72+
++g_operation.counter;
3773
}
38-
if(string && !message_length)
74+
if (string && !message_length)
3975
{
40-
//send 0
41-
printf("Sending end of string\n");
42-
i = 8;
43-
while(i--)
44-
{
45-
printf("sending bit\n");
46-
kill(operation.server_pid, SIGUSR1);
47-
pause();
48-
}
49-
return;
76+
g_operation.shift_count = 8;
77+
while (g_operation.shift_count-- && send_singal(0))
78+
pause();
79+
return ;
5080
}
51-
while(message_length--)
52-
{
53-
kill(operation.server_pid, SIGUSR1);
81+
while (message_length-- && send_singal(0))
5482
pause();
55-
}
56-
//done sending message length
57-
kill(operation.server_pid, SIGUSR2);
58-
return;
83+
send_singal(1);
84+
pause();
85+
return ;
5986
}
6087

6188
int
62-
main (int argc, char **argv)
89+
main(int argc, char **argv)
6390
{
6491
struct sigaction s_sigaction;
6592
struct sigaction s_sigaction2;
@@ -70,23 +97,16 @@ main (int argc, char **argv)
7097
s_sigaction2.sa_flags = SA_SIGINFO;
7198
sigaction(SIGUSR1, &s_sigaction, 0);
7299
sigaction(SIGUSR2, &s_sigaction2, 0);
73-
74100
if (argc != 3 || !strlen(argv[2]))
75101
{
76102
printf("Argument count %d\n", argc);
77103
return (1);
78104
}
79-
//check that the server's pid is valid/// TODO
80-
operation.server_pid = atoi(argv[1]);
81-
//
82-
operation.message = argv[2];
83-
operation.message_length = strlen(operation.message);
84-
//sending message length to server
85-
send_char(NULL, operation.message_length);
105+
g_operation.server_pid = atoi(argv[1]);
106+
g_operation.message = argv[2];
107+
g_operation.message_length = strlen(g_operation.message);
108+
send_char(NULL, g_operation.message_length);
86109
pause();
87-
//sending messae
88-
printf("Sending message \n");
89-
send_char(operation.message, 0);
90-
printf("Done sending message\n");
91-
return(0);
110+
send_char(g_operation.message, 0);
111+
return (0);
92112
}

client.o

-3.72 KB
Binary file not shown.

minitalk.a

-8.31 KB
Binary file not shown.

minitalk.h

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,43 @@
1-
//define header file (to prevent to autoinclude more than once)
2-
#ifndef MINITALK_H
3-
#define MINITALK_H
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* minitalk.h :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: hardy <hardy@student.42.fr> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2022/04/20 18:42:55 by hardy #+# #+# */
9+
/* Updated: 2022/04/20 19:36:55 by hardy ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
412

5-
#include <sys/types.h>
6-
#include <signal.h>
7-
#include <string.h>
8-
#include <stdlib.h>
9-
#include <unistd.h>
10-
#include <string.h>
11-
#include <stdio.h>
13+
#ifndef MINITALK_H
14+
# define MINITALK_H
1215

13-
typedef struct server_status_t
14-
{
15-
int send_next;
16-
int resend;
17-
int pause;
18-
int message_length;
19-
int done;
20-
int server_pid;
21-
char *message;
22-
int client_pid;
23-
int stage;
24-
void *context;
25-
} status_t;
16+
# include <sys/types.h>
17+
# include <signal.h>
18+
# include <string.h>
19+
# include <stdlib.h>
20+
# include <unistd.h>
21+
# include <string.h>
22+
# include <stdio.h>
2623

27-
typedef struct info_db_t
24+
typedef struct s_operation_db
2825
{
29-
int coutner;
30-
void *context;
31-
int client_pid;
32-
char *message;
33-
int message_length;
34-
int counter;
35-
int error;
36-
int stage;
37-
int shift_count;
38-
} data;
26+
int server_pid;
27+
void *context;
28+
int client_pid;
29+
char *message;
30+
int message_length;
31+
int counter;
32+
int stage;
33+
int shift_count;
34+
} t_data;
3935

36+
int send_singal(int type);
4037
void send_char(char *string, int message_length);
4138
void resume(int signo, siginfo_t *info, void *context);
42-
void get_length (int signo, siginfo_t *info, void *context);
43-
void alocate_mem (int signo, siginfo_t *info, void *context);
44-
void get_message (int signo, siginfo_t *info, void *context);
39+
void get_length(int signo, siginfo_t *info, void *context);
40+
void alocate_mem(int signo, siginfo_t *info, void *context);
41+
void get_message(int signo, siginfo_t *info, void *context);
4542

4643
#endif

0 commit comments

Comments
 (0)