Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My recs #1

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
15 changes: 5 additions & 10 deletions http/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ extern "C" {
}
#include <iostream>
#include <string>
#include <vector>
#include <strings.h>
#include <string.h>
#include <unistd.h>

#define BUFFER_SIZE 10000

void Http::connect(std::string url) {
extern int h_errno;
const char *nameC = url.c_str();
Expand All @@ -35,15 +33,12 @@ void Http::connect(std::string url) {
}

std::string Http::makeRequest(const char *req) {
constexpr auto BUFFER_SIZE = 10000;
send(Http::sck, req, std::string(req).length(), 0);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string(req).length() should be std::strlen(req) mah b.

char* buffer = (char *)malloc(BUFFER_SIZE);
memset(buffer, 0, BUFFER_SIZE);
std::string response;
sleep(1);
read(Http::sck, buffer, BUFFER_SIZE-1);
response = std::string(buffer);
//std::cout<<response;
return response;
std::vector<char> buffer(BUFFER_SIZE);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you really were to malloc, the most C++-ish thing here would've been
auto buffer = static_cast<char*>(std::malloc(BUFFER_SIZE));

read(Http::sck, buffer.data(), buffer.size());
return {buffer.data()};
}

std::string Http::dropHeaders(std::string doc) {
Expand Down