basic structure and client process chain done
This commit is contained in:
parent
77657c7078
commit
83bd6fb796
21 changed files with 313 additions and 7 deletions
47
src/djumbai_client_send/djumbai_client_send.c
Normal file
47
src/djumbai_client_send/djumbai_client_send.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "../../libs/protocol/protocol.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main() {
|
||||
|
||||
int pipe_to_child[2];
|
||||
|
||||
if (pipe(pipe_to_child) == -1) {
|
||||
perror("pipe");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid == -1) {
|
||||
perror("fork");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (pid == 0) { // Child process
|
||||
close(pipe_to_child[1]); // Close write end of pipe
|
||||
|
||||
// Redirect stdin to read from pipe_to_child
|
||||
dup2(pipe_to_child[0], STDIN_FILENO);
|
||||
|
||||
execlp("./bin/djumbai_enqueue/djumbai_enqueue", "djumbai_enqueue", NULL);
|
||||
|
||||
// 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
|
||||
|
||||
unsigned char buffer[sizeof(struct Message)];
|
||||
read(0, buffer, sizeof(struct Message));
|
||||
write(pipe_to_child[1], buffer, sizeof(buffer));
|
||||
|
||||
// Close the write end of the pipe
|
||||
close(pipe_to_child[1]);
|
||||
// Wait for the child process to finish
|
||||
wait(NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
0
src/djumbai_client_send/djumbai_client_send.h
Normal file
0
src/djumbai_client_send/djumbai_client_send.h
Normal file
Loading…
Add table
Add a link
Reference in a new issue