Added some error checking
This commit is contained in:
parent
9e94f77a83
commit
5e0069871e
@ -1,6 +1,7 @@
|
||||
#include "network.hpp"
|
||||
#include <arpa/inet.h>
|
||||
#include <stdlib.h> // Needed for exit()
|
||||
#include <string.h> // Needed for strcpy() and strlen()
|
||||
#include <iostream>
|
||||
|
||||
void HandleClient(int browser_s, int server_s) {
|
||||
@ -9,16 +10,24 @@ void HandleClient(int browser_s, int server_s) {
|
||||
ssize_t buf_len; // Buffer length for file reads
|
||||
|
||||
// Pass GET along from browser to server
|
||||
std::cout << "Attempting to send to server" << std::endl;
|
||||
do {
|
||||
buf_len = recv(browser_s, in_buf, BUF_SIZE, 0);
|
||||
if (buf_len == -1) {
|
||||
std::cout << "ERROR - recv returned -1" << std::endl;
|
||||
std::terminate();
|
||||
}
|
||||
send(server_s, in_buf, buf_len, 0);
|
||||
} while (buf_len != 0);
|
||||
std::cout << "Sent to server" << std::endl;
|
||||
|
||||
// Pass response along from server to browser
|
||||
std::cout << "Attempting to send to browser" << std::endl;
|
||||
do {
|
||||
buf_len = recv(server_s, out_buf, BUF_SIZE, 0);
|
||||
send(browser_s, out_buf, buf_len, 0);
|
||||
} while (buf_len != 0);
|
||||
std::cout << "Sent to browser" << std::endl;
|
||||
close(server_s);
|
||||
close(browser_s);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user