Fixed endless loading webpage
This commit is contained in:
parent
abab69344a
commit
b3c970beb4
@ -1,7 +1,8 @@
|
||||
#include "network.hpp"
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h> // Needed for exit()
|
||||
#include <string.h> // Needed for strcpy() and strlen()
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
void TestSockets(int sender_s, int receiver_s) {
|
||||
@ -45,19 +46,24 @@ void TestSockets(int sender_s, int receiver_s) {
|
||||
void PipeSockets(int sender_s, int receiver_s) {
|
||||
char in_buf[BUF_SIZE]; // Input buffer for GET resquest
|
||||
ssize_t buf_len; // Buffer length for file reads
|
||||
//
|
||||
|
||||
// Pass GET along from browser to server
|
||||
std::cout << "Attempting to send data to receiver" << std::endl;
|
||||
do {
|
||||
// Receive
|
||||
buf_len = recv(sender_s, in_buf, BUF_SIZE, 0);
|
||||
std::cout << "LOG (info) - pipe packet recv size: " << buf_len << std::endl;
|
||||
std::cout << "LOG (info) - pipe packet recv size: " << buf_len << '\n';
|
||||
if (buf_len == -1) {
|
||||
std::cout << "ERROR (info) - recv" << std::endl;
|
||||
close(sender_s);
|
||||
close(receiver_s);
|
||||
return;
|
||||
}
|
||||
if (buf_len == 0) { break; }
|
||||
if (buf_len == 0) { continue; }
|
||||
|
||||
// Send
|
||||
buf_len = send(receiver_s, in_buf, buf_len, 0);
|
||||
std::cout << "LOG (info) - pipe packet send size: " << buf_len << std::endl;
|
||||
std::cout << "LOG (info) - pipe packet send size: " << buf_len << '\n';
|
||||
} while (buf_len == BUF_SIZE);
|
||||
std::cout << "Sent data to receiver" << std::endl;
|
||||
|
||||
@ -70,19 +76,19 @@ void ProxySockets(int sender_s, int receiver_s) {
|
||||
// Pass response along from server to browser
|
||||
std::cout << "Attempting to send to browser" << std::endl;
|
||||
do {
|
||||
// Receive
|
||||
buf_len = recv(sender_s, out_buf, BUF_SIZE, 0);
|
||||
std::cout << "LOG (info) - proxy packet recv size: " << buf_len << std::endl;
|
||||
std::cout << "LOG (info) - proxy packet recv size: " << buf_len << '\n';
|
||||
if (buf_len == -1) {
|
||||
std::cout << "ERROR (info) - recv -1" << std::endl;
|
||||
return;
|
||||
}
|
||||
if (buf_len == 0) {
|
||||
std::cout << "ERROR (info) - recv 0" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Send
|
||||
buf_len = send(receiver_s, out_buf, buf_len, 0);
|
||||
std::cout << "LOG (info) - proxy packet send size: " << buf_len << std::endl;
|
||||
} while (buf_len == BUF_SIZE);
|
||||
if (buf_len == 96) { break; }
|
||||
std::cout << "LOG (info) - proxy packet send size: " << buf_len << '\n';
|
||||
} while ((buf_len == BUF_SIZE) || (buf_len == 40));
|
||||
std::cout << "Sent to browser" << std::endl;
|
||||
close(sender_s);
|
||||
close(receiver_s);
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <string.h> // Needed for strcpy() and strlen()
|
||||
#include <fcntl.h> // Needed for file i/o constants
|
||||
#include <sys/stat.h> // Needed for file i/o constants
|
||||
#include <errno.h>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
@ -154,7 +155,16 @@ void ClientRequest(int client_s) {
|
||||
do {
|
||||
buf_len = read(fh, out_buf, BUF_SIZE);
|
||||
buf_len = send(client_s, out_buf, buf_len, 0);
|
||||
if (buf_len == -1) {
|
||||
std::cerr << "ERROR (info) - send -1\n";
|
||||
std::cerr << "File causing error: " << &file_name[1] << '\n';
|
||||
std::cerr << "Errno: " << errno << '\n';
|
||||
std::cout << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << "LOG (info) - webserver send size: " << buf_len << '\n';
|
||||
} while (buf_len == BUF_SIZE);
|
||||
std::cout << std::endl;
|
||||
close(fh);
|
||||
}
|
||||
// Close the client socket and end the thread
|
||||
|
Loading…
Reference in New Issue
Block a user