Skip to content
Snippets Groups Projects
Commit ba87f81b authored by Clément's avatar Clément
Browse files

proxy

parent 5acc1ab6
Branches
No related merge requests found
Pipeline #107590 failed with stages
in 3 seconds
......@@ -8,11 +8,14 @@
#include "server/server.h"
#include <sys/poll.h>
#include <unistd.h>
#include "utils/generateur_erreur.h"
#define ERROR_RATE 0.1
#define MAX_ERROR 3
void proxy_thread(int client, void *arg)
{
struct sockaddr_in *addr = arg;
char buff[1024];
uint32_t buff;
int server;
if ((server = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
......@@ -30,24 +33,24 @@ void proxy_thread(int client, void *arg)
CHK(poll(fds, 2, -1));
ssize_t len;
if (fds[0].revents != 0) {
if ((len = recv(client, buff, sizeof(buff), 0)) <= 0)
if ((len = recv(client, &buff, sizeof(buff), 0)) <= 0)
break;
if (send(server, buff, len, 0) <= 0)
buff = generate_error(buff, ERROR_RATE, MAX_ERROR);
if (send(server, &buff, len, 0) <= 0)
break;
fds[0].revents = 0;
}
if (fds[1].revents != 0) {
if ((len = recv(server, buff, sizeof(buff), 0)) <= 0)
if ((len = recv(server, &buff, sizeof(buff), 0)) <= 0)
break;
if (send(client, buff, len, 0) <= 0)
if (send(client, &buff, len, 0) <= 0)
break;
fds[1].revents = 0;
}
}
close(server);
close(client);
return;
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment