cake
/
p7utils
Archived
1
0
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
p7utils/src/p7servtest/main.c

75 lines
1.8 KiB
C

/* ************************************************************************** */
/* _____ _ */
/* main.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: p7test | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2017/01/13 00:52:18 |___/ */
/* */
/* ************************************************************************** */
#include "main.h"
#include <unistd.h>
#include <libp7.h>
/**
* init:
* Let's go baby.
*
* @arg sin the server input.
* @arg sout the server output.
* @arg cin the client input.
* @arg cout the client output.
*/
static void init(int sin, int sout, int cin, int cout)
{
/* everybody do the fork */
pid_t pid = fork();
if (pid == (pid_t)-1)
return ;
/* yay */
if (!pid) run_server(sin, sout);
else {
sleep(1);
run_client(cin, cout);
}
}
/**
* main:
* A handful of feet.
*
* @arg ac the arguments count.
* @arg av the arguments values.
* @return the error code (0 if ok).
*/
int main(int ac, char **av)
{
/* parse the arguments */
if (parse_args(ac, av))
return (0);
/* create the pipes */
int fds1[2], fds2[2];
if (pipe(fds1)) {
fprintf(stderr,
"Unable to make the first set of pipes (server to client)\n");
return (1);
}
if (pipe(fds2)) {
fprintf(stderr,
"Unable to make the second set of pipes (client to server)\n");
close(fds1[0]);
close(fds1[1]);
return (1);
}
/* initialize. */
init(fds1[0], fds2[1], fds2[0], fds1[1]);
/* everything went well. */
return (0);
}