Done until djumbai-send
This commit is contained in:
parent
83bd6fb796
commit
da345fc422
8 changed files with 135 additions and 36 deletions
|
@ -21,18 +21,16 @@ int send_message(unsigned int sender, unsigned int receiver) {
|
|||
// Redirect stdin to read from pipe_to_child
|
||||
dup2(pipe_to_child[0], STDIN_FILENO);
|
||||
|
||||
|
||||
// Execute a command, for example, a simple "cat" command
|
||||
execlp("./bin/djumbai_client_send/djumbai_client_send", "djumbai_client_send", NULL);
|
||||
close(pipe_to_child[0]);
|
||||
|
||||
// If execlp fails
|
||||
perror("execlp");
|
||||
close(pipe_to_child[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
} else { // Parent process
|
||||
close(pipe_to_child[0]); // Close read end of pipe
|
||||
|
||||
printf("Please enter your message (Max of %ld bytes):\n", MAX_CONTENT_SIZE);
|
||||
printf("Please enter your message (Max of %ld bytes):\n", MAX_CONTENT_SIZE - 1);
|
||||
char content[MAX_CONTENT_SIZE];
|
||||
fgets(content, MAX_CONTENT_SIZE, stdin);
|
||||
|
||||
|
@ -42,13 +40,13 @@ int send_message(unsigned int sender, unsigned int receiver) {
|
|||
}
|
||||
|
||||
// Serialize the message
|
||||
unsigned char buffer[sizeof(struct Message)];
|
||||
if (serialize_message(&msg, sizeof(struct Message), buffer) == -1) {
|
||||
unsigned char buffer[MESSAGE_SIZE];
|
||||
if (serialize_message(&msg, MESSAGE_SIZE, buffer) == -1) {
|
||||
fprintf(stderr, "Error: Serialization failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
write(pipe_to_child[1], buffer, sizeof(buffer));
|
||||
write(pipe_to_child[1], buffer, MESSAGE_SIZE);
|
||||
|
||||
// Close the write end of the pipe
|
||||
close(pipe_to_child[1]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue